L
lufang
Unregistered / Unconfirmed
GUEST, unregistred user!
因工作需要,需要读取PB编译的EXE文件的版本,以下代码对于一般的可执行文件都能正确得到结果,但对于PB编译的EXE却什么都读不出来,但WINDOWS的属性页里却能读出,请问这是为什么?对了,读PB的EXE时,CodePage,LanguageID的值 和别的EXE不一样,是否和这有关,如何解决?<br>如下代码:<br>procedure TForm1.Button2Click(Sender: TObject);<br>const<br> SNotAvailable = 'Value Not Available';<br>var<br> LanguageID: string;<br> CodePage: string;<br> TranslationLength: Cardinal;<br> TranslationTable: Pointer;<br> InfoSize, Temp, Len: DWord;<br> InfoBuf: Pointer;<br> CompanyName, FileDescription, FileVersion, InternalName, LegalCopyright:<br> string;<br> LegalTradeMarks, OriginalFilename, ProductName, ProductVersion, Comments:<br> string;<br> Value: PChar;<br> LookupString, FilePath: string;<br> FVersionInfoAvailable: Boolean;<br> a:string;<br>begin<br> FilePath := 'd:/windows/regedit.exe';//windows带的<br> filepath:='e:/PSSETUP.EXE';//用PB编译的<br> InfoSize := GetFileVersionInfoSize(PChar(FilePath), Temp);<br> FVersionInfoAvailable := InfoSize > 0;<br> if FVersionInfoAvailable then<br> begin<br> InfoBuf := AllocMem(InfoSize);<br> try<br> GetFileVersionInfo(PChar(FilePath), 0, InfoSize, InfoBuf);<br> if VerQueryValue(InfoBuf, '/VarFileInfo/Translation', TranslationTable,<br> TranslationLength) then<br> begin<br> CodePage := Format('%.4x', [HiWord(PLongInt(TranslationTable)^)]);<br> LanguageID := Format('%.4x', [LoWord(PLongInt(TranslationTable)^)]);<br> end;<br><br> LookupString := 'StringFileInfo/' + LanguageID + CodePage + '/';<br> if VerQueryValue(InfoBuf, PChar(LookupString + 'CompanyName'),<br> Pointer(Value), Len) then<br> CompanyName := Value;<br> if VerQueryValue(InfoBuf, PChar(LookupString + 'FileDescription'),<br> Pointer(Value), Len) then<br> FileDescription := Value;<br> if VerQueryValue(InfoBuf, PChar(LookupString + 'FileVersion'),<br> Pointer(Value), Len) then<br> FileVersion := Value;<br> if VerQueryValue(InfoBuf, PChar(LookupString + 'InternalName'),<br> Pointer(Value), Len) then<br> InternalName := Value;<br> if VerQueryValue(InfoBuf, PChar(LookupString + 'LegalCopyright'),<br> Pointer(Value), Len) then<br> LegalCopyright := Value;<br> if VerQueryValue(InfoBuf, PChar(LookupString + 'LegalTrademarks'),<br> Pointer(Value), Len) then<br> LegalTradeMarks := Value;<br> if VerQueryValue(InfoBuf, PChar(LookupString + 'OriginalFilename'),<br> Pointer(Value), Len) then<br> OriginalFilename := Value;<br> if VerQueryValue(InfoBuf, PChar(LookupString + 'ProductName'),<br> Pointer(Value), Len) then<br> ProductName := Value;<br> if VerQueryValue(InfoBuf, PChar(LookupString + 'ProductVersion'),<br> Pointer(Value), Len) then<br> ProductVersion := Value;<br> if VerQueryValue(InfoBuf, PChar(LookupString + 'Comments'),<br> Pointer(Value), Len) then<br> Comments := Value;<br> finally<br> FreeMem(InfoBuf, InfoSize);<br> end;<br> end<br> else<br> begin<br> CompanyName := SNotAvailable;<br> FileDescription := SNotAvailable;<br> FileVersion := SNotAvailable;<br> InternalName := SNotAvailable;<br> LegalCopyright := SNotAvailable;<br> LegalTrademarks := SNotAvailable;<br> OriginalFilename := SNotAvailable;<br> ProductName := SNotAvailable;<br> ProductVersion := SNotAvailable;<br> Comments := SNotAvailable;<br> end;<br> Memo1.Lines.Clear;<br> Memo1.Lines.Add(CompanyName);<br> Memo1.Lines.Add(FileDescription);<br> Memo1.Lines.Add(FileVersion);<br> Memo1.Lines.Add(InternalName);<br> Memo1.Lines.Add(LegalCopyright);<br> Memo1.Lines.Add(LegalTrademarks);<br> Memo1.Lines.Add(OriginalFilename);<br> Memo1.Lines.Add(ProductName);<br> Memo1.Lines.Add(ProductVersion);<br> Memo1.Lines.Add(Comments);<br>end;