使用GetFileVersionInfo( ),VerQueryValue( )等函数的问题 |
答題得分者是:RaynorPao
|
bigdogchina
版主 發表:238 回覆:523 積分:312 註冊:2003-04-28 發送簡訊給我 |
大大们好,小弟我:问题多多,错综复杂,束手无策,盼您点拨
我想读出程式的版本信息,翻遍>
>
同时也查询了站内的相关内容:
class="code">
void __fastcall TForm1::Button1Click(TObject *Sender)
{
union
{
int Int;
char ch[4];
}i_c; DWORD dwHandle,dwSize,dwLangueID;
char *Block,*Tran;
char Buf[256];
UINT Len;
AnsiString Item;
AnsiString sPath = "C:\\Winnt\\Explorer.exe"; dwSize = GetFileVersionInfoSize(sPath.c_str(),&dwHandle);
if(dwSize == 0) return; //无版本信息
dwSize ;
Block = new char[dwSize];
GetFileVersionInfo(sPath.c_str(),dwHandle,dwSize,(void *)Block);
VerQueryValue(Block,"\\VarFileInfo\\Translation",(void **)&Tran,&Len);
i_c.ch[0] = Tran[0];
i_c.ch[1] = Tran[1];
i_c.ch[2] = Tran[2];
i_c.ch[3] = Tran[3];
dwLangueID = i_c.Int; //得到语言版本号
Item = "\\StringFileInfo\\";
Item = Item IntToStr(dwLangueID) "\\ProductName";
if(VerQueryValue(Block,Item.c_str(),(void **)&Buf,&Len))
{
ShowMessage(Buf); //显示程式名称
}
}
我高高兴兴的按下Run,等着秀出程式名Explorer.exe,可是,现实和希望总是相反的,什么都没有,连个
------
人生在勤,不索何获? |
collonil
中階會員 發表:13 回覆:56 積分:63 註冊:2003-03-26 發送簡訊給我 |
|
bigdogchina
版主 發表:238 回覆:523 積分:312 註冊:2003-04-28 發送簡訊給我 |
|
collonil
中階會員 發表:13 回覆:56 積分:63 註冊:2003-03-26 發送簡訊給我 |
|
RaynorPao
版主 發表:139 回覆:3622 積分:7025 註冊:2002-08-12 發送簡訊給我 |
bigdogchina 你好:
試試看這樣寫可不可以達到目的呢??
< class="code">
DWORD dwVerInfoSize=0;
dwVerInfoSize=GetFileVersionInfoSize("C:\\Winnt\\explorer.exe", &dwVerInfoSize);
BYTE *bVerInfoBuf=new BYTE[dwVerInfoSize];
if(GetFileVersionInfo("C:\\Winnt\\explorer.exe", 0, dwVerInfoSize, bVerInfoBuf))
{
VS_FIXEDFILEINFO *vsInfo;
UINT vsInfoSize;
if(VerQueryValue(bVerInfoBuf, "\\", (void**)&vsInfo, &vsInfoSize))
{
int iFileVerMajor=HIWORD(vsInfo->dwFileVersionMS);
int iFileVerMinor=LOWORD(vsInfo->dwFileVersionMS);
int iFileVerRelease=HIWORD(vsInfo->dwFileVersionLS);
int iFileVerBuild=LOWORD(vsInfo->dwFileVersionLS);
ShowMessage(IntToStr(iFileVerMajor) "." IntToStr(iFileVerMinor) "."
IntToStr(iFileVerRelease) "." IntToStr(iFileVerBuild));
}
}
delete bVerInfoBuf;
-- Enjoy Researching & Developing --
------
-- 若您已經得到滿意的答覆,請適時結案!! -- -- 欲知前世因,今生受者是;欲知來世果,今生做者是 -- -- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 -- |
bigdogchina
版主 發表:238 回覆:523 積分:312 註冊:2003-04-28 發送簡訊給我 |
虔诚的感谢collonil,RaynorPao两位大大,您们辛苦了!!!
collonil大哥,我有个不情之请,您能否把code贴出来,我很想拜读您的大做,希望您满足我这个愿望,好吗?
>,不过小弟我反应迟钝,仍然有个问题未解:直接用>
>
我想将
<>
">
都秀出来.劳您费心了.
我今天一上午都在仔细琢磨到底我的代码问题出在那?后来在>
>
注意哦,语言版本是 class="code">
int __fastcall TForm1::MyIntToHex(int Int,char Hex[],bool Add0x)
{
struct hex_struct
{
unsigned eight : 4;
unsigned seven : 4;
unsigned six : 4;
unsigned five : 4;
unsigned four : 4;
unsigned three : 4;
unsigned two : 4;
unsigned one : 4;
};
union
{
unsigned Int;
hex_struct Hex;
}ih;
ih.Int = (unsigned)Int;
int i = 0;
if(Add0x)
{
Hex[i ]='0';
Hex[i ]='x';
}
Hex[i ]=Num_Char(ih.Hex.one);
Hex[i ]=Num_Char(ih.Hex.two);
Hex[i ]=Num_Char(ih.Hex.three);
Hex[i ]=Num_Char(ih.Hex.four);
Hex[i ]=Num_Char(ih.Hex.five);
Hex[i ]=Num_Char(ih.Hex.six);
Hex[i ]=Num_Char(ih.Hex.seven);
Hex[i ]=Num_Char(ih.Hex.eight);
Hex[i]='\0';
return i;
}
char __fastcall TForm1::Num_Char(unsigned numeric)
{
const Asc0=48;
const AscA=65-10;
if(numeric<=9)return char(Asc0 numeric);
if((numeric>=10)&&(numeric<=15))return char(AscA numeric);
return ' ';
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
union
{
int Int;
char ch[4];
}i_c; DWORD dwHandle,dwSize,dwBytes,dwLangueID;
char *Block,*Tran;
char Buf[256];
char Hex[14];
UINT Len;
AnsiString Item;
AnsiString sPath = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE"; dwSize = GetFileVersionInfoSize(sPath.c_str(),&dwHandle);
if(dwSize == 0) return; //无版本信息
dwSize ;
Block = new char[dwSize];
GetFileVersionInfo(sPath.c_str(),dwHandle,dwSize,(void *)Block);
VerQueryValue(Block,"\\VarFileInfo\\Translation",(void **)&Tran,&Len);
i_c.ch[0] = Tran[0];
i_c.ch[1] = Tran[1];
i_c.ch[2] = Tran[2];
i_c.ch[3] = Tran[3];
dwLangueID = i_c.Int;
Item = "\\StringFileInfo\\";
MyIntToHex(dwLangueID,Hex,false); //将其语言版本转换为16进制
Item = Item Hex "\\FileDescription";
if(VerQueryValue(Block,Item.c_str(),(void **)&Buf,&Len))
{
ShowMessage(Buf);
}
}
结果还是一样,执行VerQueryValue()时,仍然返回false.天啊,VerQueryValue()要求的每个参数,我都按它的要求去做了,为什么还是返回false啊,看来实在不行,也只有放弃了 發表人 -
------
人生在勤,不索何获? |
axsoft
版主 發表:681 回覆:1056 積分:969 註冊:2002-03-13 發送簡訊給我 |
bigdogchina您好:
參考這個元件試試
TWSAExeVersion
下載: http://delphi.ktop.com.tw/loadfile.php?TOPICID=10836073&CC=242347 檔案來源已經不可考了! TWSAExeVersion
============== This component allows the developer to extract version information about a Borland C++ Builder
application at run time. It can be placed on a form and version information can be accessed
through the following properties: CompanyName
FileDescription
FileVersion
InternalName
LegalCopyright
LegalTrademarks
OriginalFilename
ProductName
ProductVersion
Comments
MajorVersion
MinorVersion
Release
Build Component Files:
WSAExeVersion.cpp
WSAExeVersion.h
WSAExeVersion.res Package Files:
WSASystem.bpk
WSASystem.cpp
WSASystem.res Example Files:
AboutDlg.cpp
AboutDlg.dfm
AboutDlg.h
Author contact information:
Peter Tersteeg.
Westinghouse Signals Australia.
ptersteeg@westsig.com.au
Comments:
I wrote this component because I found there was a lot of people requesting code to retrieve
version information. If you find this component useful, find/fix any bugs or enhance it in any
way, please let me know. Otherwise feel free to use it in any way. HAVE A NICE DAY FOR YOU
|
RaynorPao
版主 發表:139 回覆:3622 積分:7025 註冊:2002-08-12 發送簡訊給我 |
引言: 虔诚的感谢collonil,RaynorPao两位大大,您们辛苦了!!! collonil大哥,我有个不情之请,您能否把code贴出来,我很想拜读您的大做,希望您满足我这个愿望,好吗? >,不过小弟我反应迟钝,仍然有个问题未解:直接用> > 我想将 <> "> 都秀出来.劳您费心了. 我今天一上午都在仔细琢磨到底我的代码问题出在那?后来在> > 注意哦,语言版本是 class="code"> int __fastcall TForm1::MyIntToHex(int Int,char Hex[],bool Add0x) { struct hex_struct { unsigned eight : 4; unsigned seven : 4; unsigned six : 4; unsigned five : 4; unsigned four : 4; unsigned three : 4; unsigned two : 4; unsigned one : 4; }; union { unsigned Int; hex_struct Hex; }ih; ih.Int = (unsigned)Int; int i = 0; if(Add0x) { Hex[i ]='0'; Hex[i ]='x'; } Hex[i ]=Num_Char(ih.Hex.one); Hex[i ]=Num_Char(ih.Hex.two); Hex[i ]=Num_Char(ih.Hex.three); Hex[i ]=Num_Char(ih.Hex.four); Hex[i ]=Num_Char(ih.Hex.five); Hex[i ]=Num_Char(ih.Hex.six); Hex[i ]=Num_Char(ih.Hex.seven); Hex[i ]=Num_Char(ih.Hex.eight); Hex[i]='\0'; return i; } char __fastcall TForm1::Num_Char(unsigned numeric) { const Asc0=48; const AscA=65-10; if(numeric<=9)return char(Asc0 numeric); if((numeric>=10)&&(numeric<=15))return char(AscA numeric); return ' '; } void __fastcall TForm1::Button1Click(TObject *Sender) { union { int Int; char ch[4]; }i_c; DWORD dwHandle,dwSize,dwBytes,dwLangueID; char *Block,*Tran; char Buf[256]; char Hex[14]; UINT Len; AnsiString Item; AnsiString sPath = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE"; dwSize = GetFileVersionInfoSize(sPath.c_str(),&dwHandle); if(dwSize == 0) return; //无版本信息 dwSize ; Block = new char[dwSize]; GetFileVersionInfo(sPath.c_str(),dwHandle,dwSize,(void *)Block); VerQueryValue(Block,"\\VarFileInfo\\Translation",(void **)&Tran,&Len); i_c.ch[0] = Tran[0]; i_c.ch[1] = Tran[1]; i_c.ch[2] = Tran[2]; i_c.ch[3] = Tran[3]; dwLangueID = i_c.Int; Item = "\\StringFileInfo\\"; MyIntToHex(dwLangueID,Hex,false); //将其语言版本转换为16进制 Item = Item Hex "\\FileDescription"; if(VerQueryValue(Block,Item.c_str(),(void **)&Buf,&Len)) { ShowMessage(Buf); } } 结果还是一样,执行VerQueryValue()时,仍然返回false.天啊,VerQueryValue()要求的每个参数,我都按它的要求去做了,为什么还是返回false啊,看来实在不行,也只有放弃了 >>< face="Verdana, Arial, Helvetica"> bigdogchina 你好: 請問?? 你說的是不是像這個樣子呢?? < class="code"> #include "stdio.h" DWORD dwVerInfoSize=0; dwVerInfoSize=GetFileVersionInfoSize("C:\\Winnt\\explorer.exe", &dwVerInfoSize); BYTE *bVerInfoBuf=new BYTE[dwVerInfoSize]; if(GetFileVersionInfo("C:\\Winnt\\explorer.exe", 0, dwVerInfoSize, bVerInfoBuf)) { LPDWORD lang; UINT len, i, j; char buffer[MAX_PATH]; VerQueryValue(bVerInfoBuf, "\\VarFileInfo\\Translation", (void**)&lang, &len); for(i=0; i
------
-- 若您已經得到滿意的答覆,請適時結案!! -- -- 欲知前世因,今生受者是;欲知來世果,今生做者是 -- -- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 -- |
bigdogchina
版主 發表:238 回覆:523 積分:312 註冊:2003-04-28 發送簡訊給我 |
|
bigdogchina
版主 發表:238 回覆:523 積分:312 註冊:2003-04-28 發送簡訊給我 |
|
RaynorPao
版主 發表:139 回覆:3622 積分:7025 註冊:2002-08-12 發送簡訊給我 |
引言: RaynorPao大大,不知您有否发现,当程式是英文版本的时候,能顺利的读出,当是中文版本的时候,就读不出来了哦.比如C:\WINNT\system32\internat.exe就读不出来 人生在勤,不索何获? >>< face="Verdana, Arial, Helvetica"> bigdogchina 你好: 小弟我的讀得出來耶,以下是讀出來的結果 < class="code"> CompanyName: Microsoft Corporation FileDescription: Keyboard Language Indicator Applet FileVersion: 5.00.2920.0000 InternalName: INTERNAT LegalCopyright: Copyright (C) Microsoft Corp. 1994-1999 OriginalFilename: INTERNAT.EXE ProductName: Microsoft(R) Windows (R) 2000 Operating System ProductVersion: 5.00.2920.0000 -- Enjoy Researching & Developing --
------
-- 若您已經得到滿意的答覆,請適時結案!! -- -- 欲知前世因,今生受者是;欲知來世果,今生做者是 -- -- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 -- |
bigdogchina
版主 發表:238 回覆:523 積分:312 註冊:2003-04-28 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |