如何检测系统有无某个控件,如FLASH 的OCX,并且其版本是什么?
如何检测系统有无FLASH 控件,并且其版本是什么? 问题点数:50、回复次数:2Top
1 楼ruanyuping()回复于 2003-09-01 12:17:43 得分 0
upTop
2 楼bcpl(林平之)回复于 2003-09-01 12:33:13 得分 50
CString GetRegString(LPCTSTR lpszRegValueName)
{
CString sRegValueName(lpszRegValueName);
CString sRootKey, sSubKey, sValueName;
HKEY hRootKey, hSubKey;
const int BUF_SIZE = 256;
char buf[BUF_SIZE];
DWORD dwBufLen = BUF_SIZE;
int t1, t2;
t1 = sRegValueName.Find('\\', 0);
sRootKey = sRegValueName.Left(t1);
t2 = sRegValueName.ReverseFind('\\');
sValueName = sRegValueName.Mid(t2 + 1);
t1++;
sSubKey = sRegValueName.Mid(t1, t2 - t1);
sRootKey.MakeUpper();
if(sRootKey == "HKEY_CLASSES_ROOT")
hRootKey = HKEY_CLASSES_ROOT;
else if(sRootKey == "HKEY_CURRENT_USER")
hRootKey = HKEY_CURRENT_USER;
else if(sRootKey == "HKEY_LOCAL_MACHINE")
hRootKey = HKEY_LOCAL_MACHINE;
else if(sRootKey == "HKEY_USERS")
hRootKey = HKEY_USERS;
else if(sRootKey == "HKEY_CURRENT_CONFIG")
hRootKey = HKEY_CURRENT_CONFIG;
if(::RegOpenKeyEx(hRootKey, sSubKey, 0, KEY_QUERY_VALUE, &hSubKey) != ERROR_SUCCESS)
return "";
CString sValue;
if(::RegQueryValueEx(hSubKey, sValueName, NULL, NULL, (LPBYTE)buf, &dwBufLen) == ERROR_SUCCESS)
{
sValue = buf;
}
::RegCloseKey(hSubKey);
return sValue;
}
void COcx1Dlg::OnCheck()
{
CString sOcxFile = GetRegString("HKEY_CLASSES_ROOT\\CLSID\\{D27CDB6E-AE6D-11cf-96B8-444553540000}\\InprocServer32\\");
if(!sOcxFile.IsEmpty())
{
DWORD dw;
DWORD size = GetFileVersionInfoSize((LPTSTR)(LPCTSTR)sOcxFile, &dw);
LPVOID pData = new BYTE[size];
if(GetFileVersionInfo((LPTSTR)(LPCTSTR)sOcxFile, 0, size, pData))
{
struct LANGANDCODEPAGE
{
WORD wLanguage;
WORD wCodePage;
} *lpTranslate;
UINT cbTranslate;
VerQueryValue(pData, "\\VarFileInfo\\Translation", (LPVOID*)&lpTranslate, &cbTranslate);
CString sSubBlock;
sSubBlock.Format("\\StringFileInfo\\%04x%04x\\FileVersion", lpTranslate[0].wLanguage, lpTranslate[0].wCodePage);
LPSTR lpszVerInfo;
UINT cbVerInfo;
VerQueryValue(pData, sSubBlock.GetBuffer(0), (LPVOID*)&lpszVerInfo, &cbVerInfo);
CString sInfo;
sInfo.Format("已安装Flash控件\n文件:%s\n版本:%s", sOcxFile, lpszVerInfo);
AfxMessageBox(sInfo);
}
} // end if(!sOcxFile.IsEmpty())
}
测试程序http://my.6to23.com/cigarette/ocx1.zipTop



