-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUtilsUnit.pas
More file actions
56 lines (48 loc) · 1.46 KB
/
UtilsUnit.pas
File metadata and controls
56 lines (48 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{
Modified copypasta, original sauce:
https://stackoverflow.com/questions/17279394/getfileversioninfosize-and-getfileversioninfo-return-nothing/17286050#17286050
}
unit UtilsUnit;
interface
function GetVersion(const FileName: string): String;
implementation
uses
Winapi.Windows, System.SysUtils;
function GetVersion(const FileName: string): String;
var
iLastError: DWord;
vPVerInfo: Pointer;
vVerInfoSize: Cardinal;
vVerValueSize: Cardinal;
vWhyThisExists: Cardinal;
vPVerValue: PVSFixedFileInfo;
begin
Result := '';
iLastError := 0;
vVerInfoSize := GetFileVersionInfoSize(PChar(FileName), vWhyThisExists);
if vVerInfoSize > 0 then
begin
GetMem(vPVerInfo, vVerInfoSize);
try
if GetFileVersionInfo(PChar(FileName), 0, vVerInfoSize, vPVerInfo) then
begin
if VerQueryValue(vPVerInfo, '\', Pointer(vPVerValue), vVerValueSize) then
with vPVerValue^ do
Exit(Format('v %d.%d.%d build %d',
//
[HiWord(dwFileVersionMS), // Major
LoWord(dwFileVersionMS), // Minor
HiWord(dwFileVersionLS), // Release
LoWord(dwFileVersionLS)])); // Build
end
else
iLastError := GetLastError;
finally
FreeMem(vPVerInfo, vVerInfoSize); // this run anyway even with exit up there
end;
end
else
iLastError := GetLastError;
Result := Format('GetVersion failed: (%d) %s', [iLastError, SysErrorMessage(iLastError)]);
end;
end.