gpt4 book ai didi

c++ - 从 .exe 获取编译日期和时间

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:40:10 25 4
gpt4 key购买 nike

我有可执行文件的全名和路径,例如C:\IW4\BIN\iw32.exe,并想提取该可执行文件的编译日期和时间。

我该怎么做?我找不到任何合适的解决方案。

如果该信息有值(value)的话,我的 C++ 程序必须在 Windows 下使用 Borland C++ Builder 进行编译。

编辑:我找到了一些示例代码并且可以正常工作,感谢您的所有指示和提示!

代码是:

#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;
}

它提供以下输出:

Created: 2013-06-20 12:37:14
Size: 15098368

最佳答案

您要查找的信息可在 IMAGE_FILE_HEADER 中找到的可执行镜像。您可以通过按其在图像中的偏移量指向该字段(困难的方式)来检索此信息。另一种选择是使用 Image Help Library

关于c++ - 从 .exe 获取编译日期和时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17212518/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com