获取编译日期&来自.exe的时间 [英] Get compilation Date & Time from .exe
问题描述
C:\IW4\BIN\iw32.exe
,并提取该可执行文件的编译日期和时间。 我该怎么做?我找不到任何合适的解决方案。
我的C ++程序必须在Windows下使用Borland C ++ Builder编译,如果该信息是有价值的。
编辑:
我发现一些示例代码,它的工作原理,谢谢你所有的指针和提示!
代码是:
#include< stdio.h>
#include< windows.h>
int main(int argc,char ** argv)
{
WIN32_FILE_ATTRIBUTE_DATA attr;
SYSTEMTIME创建;
if(argc< 2)
return 1;
GetFileAttributesEx(argv [1],GetFileExInfoStandard,& attr);
FileTimeToSystemTime(& attr.ftLastWriteTime,& creation);
printf(Created:%04d-%02d-%02d%02d:%02d:%02d\\\
Size:%d bytes\\\
,
creation。 wYear,creation.wMonth,creation.wDay,
creation.wHour,creation.wMinute,creation.wSecond,
attr.nFileSizeLow);
return 0;
}
其中提供以下输出:
创建时间:2013-06-20 12:37:14
大小:15098368
您正在寻找的信息是在 IMAGE_FILE_HEADER 。您可以通过将字段指向图像中的偏移量来获取这些信息(硬的方式)。另一个选择是使用图像帮助库
I have the full name & path of an executable, e.g. C:\IW4\BIN\iw32.exe
, and want to extract the compilation date and time of that executable.
How can I do this? I couldn't find any suitable solution.
My C++ program must compile under Windows using Borland C++ Builder, if that info is of any worth.
EDIT: I found some sample code and it works, thanks for all your pointers and hints!
The Code is :
#include <stdio.h>
#include <windows.h>
int main (int argc, char** argv)
{
WIN32_FILE_ATTRIBUTE_DATA attr;
SYSTEMTIME creation;
if (argc < 2)
return 1;
GetFileAttributesEx(argv[1], GetFileExInfoStandard, &attr);
FileTimeToSystemTime(&attr.ftLastWriteTime, &creation);
printf("Created: %04d-%02d-%02d %02d:%02d:%02d\n"
"Size: %d bytes\n",
creation.wYear, creation.wMonth, creation.wDay,
creation.wHour, creation.wMinute, creation.wSecond,
attr.nFileSizeLow);
return 0;
}
Which delivers following output :
Created: 2013-06-20 12:37:14
Size: 15098368
The information your're looking for is to be found in the IMAGE_FILE_HEADER of the executable image. You can retrieve this information either by pointing the field by its offset in the image (the hard way). Another option would be to use the Image Help Library
这篇关于获取编译日期&来自.exe的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!