1 頁 (共 1 頁)

如何在程式執行過程中,讀取程式本身的資訊,類似本身版本、檔案大小、建立、修改的時間

發表於 : 2008年 11月 27日, 17:53
tim
請問各位我如何在程式執行過程中,讀取程式本身的資訊,類似本身版本、檔案大小、建立、修改的時間!!
V1, V2, V3, V4 就是您所要的版本資訊

[/CODE]
procedure GetBuildInfo(var V1, V2, V3, V4: Word);
var
VerInfoSize, VervalueSize, Dummy : DWORD;
VerInfo : Pointer;
Vervalue : PVSFixedFileInfo;
begin
VerInfoSize := GetFileVersionInfoSize(PChar(ParamStr(0)), Dummy);
GetMem(VerInfo, VerInfoSize);
GetFileVersionInfo(PChar(ParamStr(0)), 0, VerInfoSize, VerInfo);
VerQueryvalue(VerInfo, '', Pointer(Vervalue), VervalueSize);

With Vervalue^ do
begin
V1 := dwFileVersionMS shr 16; // Major Version
V2 := dwFileVersionMS and $FFFF; // Minor Version
V3 := dwFileVersionLS shr 16; // Release
V4 := dwFileVersionLS and $FFFF; // Build Number
end;
FreeMem(VerInfo, VerInfoSize);
end;

//另外,用 GetFileTime 可得到檔案大小、建立、修改的時間

//The GetFileTime function retrieves the date and time that a file was created, last accessed, and last modified.

BOOL GetFileTime(
HANDLE hFile, // handle to the file
LPFILETIME lpCreationTime, // address of creation time
LPFILETIME lpLastAccessTime, // address of last access time
LPFILETIME lpLastWriteTime // address of last write time
);//節錄自 MSDN
[/CODE]