我有一个Windows可执行文件,我已经安装在一台机器上。是否有一种方法或API可以在该计算机上安装可执行文件时获取时间戳。我不问这个exe文件的创建/修改/访问时间戳,而是exe文件安装在特定机器上的时间。 此外,该exe文件安装在Windows系统文件夹。可执行安装时间
可执行安装时间
回答
您可以使用FileTimeToSystemTime()
检索日期和一个文件或目录的创建时间。
#include <windows.h>
#include <stdio.h>
int main(){
// a file handle
HANDLE hFile1;
FILETIME ftCreate, ftAccess, ftWrite;
SYSTEMTIME stUTC, stLocal, stUTC1, stLocal1, stUTC2, stLocal2;
// a filename,
char fname1[ ] = "c:\\windows\\explorer.exe";
// temporary storage for file sizes
DWORD dwFileSize;
DWORD dwFileType;
// opening the existing file
hFile1 = CreateFile(fname1, // file to open
GENERIC_READ, // open for reading
FILE_SHARE_READ, // share for reading
NULL, // default security
OPEN_EXISTING, // existing file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attribute template
if(hFile1 == INVALID_HANDLE_VALUE){
printf("Could not open %s file, error %d\n", fname1, GetLastError());
return 4;
}
dwFileType = GetFileType(hFile1);
dwFileSize = GetFileSize(hFile1, NULL);
printf("%s size is %d bytes and file type is %d\n", fname1, dwFileSize, dwFileType);
// retrieve the file times for the file.
if(!GetFileTime(hFile1, &ftCreate, &ftAccess, &ftWrite)){
printf("Something wrong lol!\n");
return FALSE;
}
// convert the created time to local time.
FileTimeToSystemTime(&ftCreate, &stUTC);
SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
// convert the last-access time to local time.
FileTimeToSystemTime(&ftAccess, &stUTC1);
SystemTimeToTzSpecificLocalTime(NULL, &stUTC1, &stLocal1);
// convert the last-write time to local time.
FileTimeToSystemTime(&ftWrite, &stUTC2);
SystemTimeToTzSpecificLocalTime(NULL, &stUTC2, &stLocal2);
// build a string showing the date and time.
printf("\nCreated on: %02d/%02d/%d %02d:%02d\n", stLocal.wDay, stLocal.wMonth, stLocal.wYear, stLocal.wHour, stLocal.wMinute);
printf("Last accessed: %02d/%02d/%d %02d:%02d\n", stLocal1.wDay, stLocal1.wMonth, stLocal1.wYear, stLocal1.wHour, stLocal1.wMinute);
printf("Last written: %02d/%02d/%d %02d:%02d\n\n", stLocal2.wDay, stLocal2.wMonth, stLocal2.wYear, stLocal2.wHour, stLocal2.wMinute);
// close the file's handle and itself
CloseHandle(hFile1);
return 0;
}
我的印象是,创建时间是文件最初在主构建机器上创建的时间,但看起来像是我在X时间构建了一个exe文件,但是在Y时间在M机器上复制了这个exe文件,然后创建了时间M机器上的文件将是Y时间。它是否正确? – user3364310
是的,如果你将exe复制到另一个位置,那么它会得到一个新的时间戳。我更新了代码。它显示了创建日期,上次访问时间和修改时间。 –
完美。谢谢 。 – user3364310
- 1. Install4j:安装后可以安装可执行文件吗?
- 2. 安装期间Inno Setup启动可执行文件(安装驱动程序)
- 3. Wix:安装可执行程序
- 4. 安装可执行文件与Powershell DSC
- 5. 可执行的JAR安装路径
- 6. Python包安装脚本安装二进制可执行文件
- 7. Perl:inc :: Module ::在Makefile.PL中安装并安装可执行文件
- 8. 在本地安装.net安装程序可执行文件时出错
- 9. 在MSI执行期间执行的DLL(安装程序)
- 10. 无法执行时安装程序
- 11. 安装Tk执行命令时出错
- 12. Bundler安装需要较长的时间来执行
- 13. 增加drupal commons安装的最大执行时间
- 14. 单元测试执行期间的Windows 8 Appx安装超时
- 15. 以编程方式执行安装时出现安装失败
- 16. 安装包作为依赖时,不要执行postinstall安装
- 17. 安装openwrt系统时未发现ruby可执行文件
- 18. libtool安装保留了可执行文件的临时路径
- 19. 安装gem时,是否应该只安装库,还是应该安装可执行文件?
- 20. npm安装无法执行exec安装后脚本bower安装
- 21. 开始执行NSIS安装
- 22. 使用Vista进行安装时签名的安装可执行文件上的未识别出版者
- 23. 安装Winrar之后,自行执行的Jar文件不可执行
- 24. 如何改变套件安装可执行文件和安装目录
- 25. 如何创建将安装可执行文件的安装文件Jar
- 26. 在安装开始之前运行可执行文件
- 27. 通过JSPM安装后运行可执行文件
- 28. 如何在安装项目结束时运行可执行文件?
- 29. 在可变时间执行脚本
- 30. 付款可执行多长时间?
在注册表中可能有一个条目。 –
定义“已安装”。 –
安装时间表示何时将exe复制到机器上。 – user3364310