【发布时间】:2012-06-06 23:18:14
【问题描述】:
如何获取正在运行的应用程序的版本?
我一直在用GetFileVersionInfo(ParamStr(0), ...):
filename := PChar(ExtractShortPathName(ParamStr(0)));
//Get the number of bytes he have to allocate for the file information structure
dwInfoLength := GetFileVersionInfoSize(lptstrFilename, {var}dwHandle);
//Get version info
GetMem(pInfoData, dwInfoLength);
GetFileVersionInfo(lptstrFilename, dwHandle, dwInfoLength, pInfoData);
//Set what information we want to extract from pInfoData
lpSubBlock := PChar(Chr(92)+Chr(0));
//Extract the desired data from pInfoData into the FileInformation structure
VerQueryValue(pInfoData, lpSubBlock, PFileInformation, LengthOfReturned);
这种技术的问题在于它需要 Windows 加载程序到load the image before the resources can be read。我使用 IMAGE_FILE_NET_RUN_FROM_SWAP 图像标志 (in order to avoid in-page exceptions on a fiddly network) 构建我的应用程序。
这会导致 Windows 加载程序通过网络再次加载整个图像,而不是仅仅查看 “me”。由于我在启动时检查并保存了我自己的版本,因此 6 秒的应用程序启动变成了 10 秒的应用程序启动。
我如何阅读 me、my 正在运行的应用程序的版本?
我会假设 Windows 没有 API 来读取正在运行的进程的版本,只有我从中加载的文件(如果文件不再存在,则它无法读取任何版本信息)。
但我也假设有可能从我的进程自己的内存中读取版本资源(当然不是管理员或调试器组的成员)。
我可以阅读我的进程的版本吗?
相关奖励问题:我如何从我而不是通过网络加载PE Image资源?
【问题讨论】:
标签: delphi winapi resources versioning delphi-5