我有一个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. 可执行的JAR安装路径
- 4. Wix:安装可执行程序
- 5. Perl:inc :: Module ::在Makefile.PL中安装并安装可执行文件
- 6. 在本地安装.net安装程序可执行文件时出错
- 7. 在MSI执行期间执行的DLL(安装程序)
- 8. 安装Tk执行命令时出错
- 9. 安装包作为依赖时,不要执行postinstall安装
- 10. 以编程方式执行安装时出现安装失败
- 11. 安装openwrt系统时未发现ruby可执行文件
- 12. npm安装无法执行exec安装后脚本bower安装
- 13. 使用Vista进行安装时签名的安装可执行文件上的未识别出版者
- 14. 如何改变套件安装可执行文件和安装目录
- 15. 如何在安装项目结束时运行可执行文件?
- 16. 通过JSPM安装后运行可执行文件
- 17. 在可变时间执行脚本
- 18. 付款可执行多长时间?
- 19. 安装Perl日期时间
- 20. RPM - 安装时间参数
- 21. 任务执行时间高于定时器执行时间
- 22. 在高级安装程序安装结束时执行多个exe文件
- 23. Vim 7.4已安装,但在运行时执行Vim 7.3
- 24. 负执行时间
- 25. button.onclick执行时间
- 26. FlexUnit执行时间
- 27. mysql执行时间
- 28. ServiceConfigFailureActions出现Wix问题:安装期间未执行
- 29. 安装debian软件包以执行安装操作
- 30. 无法安装PostgreSQL:在Windows XP上执行Microsoft VC++运行时安装程序时发生错误
在注册表中可能有一个条目。 –
定义“已安装”。 –
安装时间表示何时将exe复制到机器上。 – user3364310