c++ 获取ie版本号
最近要实现用c++实现怎样获取ie版本号,cpu的processid这个功能,最终还是完成了,方法如下:
// Computer.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<stdio.h>
#include<Windows.h>
#include<string>
#include<fstream>
#include<iostream>
#include<iomanip>
#include<strsafe.h>
#include <stdlib.h>
#include<Nb30.h>
#include<io.h>
using namespace std;
#pragma comment(lib,"Version.lib")
#pragma comment(lib,"Netapi32.lib")
LPTSTR namebuf=new char[12];
DWORD namesize=12;
DWORD serialnumber;
DWORD maxlen;
DWORD fileflag;
LPTSTR sysnamebuf=new char[10];
DWORD sysnamesize=10;
/*
声明函数体
*/
void GetSystemVersion();
bool GetNetFrameWorkVersion() ;
void GetCurrentProgramPath(char path[]);
bool GetIeVersion(LPTSTR lpIEversion , size_t cchLen);
VOID ChangeByteOrder(PCHAR szString, USHORT uscStrSize);
void hdid9x();
void DetectIDE(BYTE bIDEDeviceMap);
void hdidnt();
void GetSystemMacAddress();
void GetSystemCpuId();
int GetMacAddress(char *mac) ;
void GetCpuID(string& strCpuID);
char szAddressDes[20];
int _tmain(int argc, char* argv[])
{
HWND hwnd=GetForegroundWindow();
SetWindowText(hwnd,"安装程序");
// wcout<<sz<<endl;
GetSystemVersion();
bool isVersion=GetNetFrameWorkVersion();
if(isVersion==false)
{
printf("正在安装.netframework v2.0.50727\n");
char p[500]={0};
GetCurrentProgramPath(p);
char c[]="microsoft_dotnetfxchs2.0.exe";
strcat(p,c);
printf("%s\n",p);
WinExec(p,SW_SHOWMAXIMIZED);
}
lbl: TCHAR sz[256] = { 0 };
int nLen = sizeof(sz)/sizeof(TCHAR);
bool cs= GetIeVersion(sz,nLen);
if(cs==false)
{
printf("您的ie版本过低,需要升级后才能继续安装!\n");
system("pause");
system("\"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE\" http://www.microsoft.com/zh-cn/download/details.aspx?id=43");
goto lbl;
}
cout<<"=================配置信息=====================\n";
/*::GetVolumeInformation("C:\\",namebuf,namesize,&serialnumber,&maxlen,&fileflag, sysnamebuf,sysnamesize);
cout << hex<<"c盘序列号:"<< serialnumber<<endl;*/
//GetSystemCpuId();
GetSystemMacAddress();
//打印出MAC
string cpuid;
GetCpuID(cpuid);
cout<<"CPU序列号为:\n"<<cpuid<<endl;
cpuid+=szAddressDes;
cout<<"ClientID:\n"<<cpuid<<endl;
char c[100]={0};
GetCurrentProgramPath(c);
char clientID[]="ClientID.txt";
strcat(c,clientID);
fstream os ;
os.open(c,ios::out);
string client_id;
GetCpuID(client_id);
client_id+=szAddressDes;
os<<client_id<<endl;
os.close();
system("pause");
return 0;
}
//获取MAC地址信息
void GetSystemMacAddress()
{
/*cout<<"获取网卡MAC地址:";
system("getmac");*/
//获取MAC
//GetSystemMacAddress();
char szAddr[20];
GetMacAddress(szAddr);
//mac地址 szAddr
int i,j;
for(i=0,j=0;i<sizeof(szAddr)/sizeof(char);i++)
{
if(szAddr[i]!='-')
{
szAddressDes[j]=szAddr[i];
j++;
}
}
/*strMac=szAddressDes;*/
cout<<"mac地址:\n"<<szAddressDes<<endl<<endl;
}
//获取MAC地址信息
int GetMacAddress(char *mac)
{
NCB ncb;
typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];
} ASTAT, * PASTAT;
ASTAT Adapter;
LANA_ENUM lana_enum;
UCHAR uRetCode;
memset( &ncb, 0, sizeof(ncb) );
memset( &lana_enum, 0, sizeof(lana_enum));
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (unsigned char *) &lana_enum;
ncb.ncb_length = sizeof(LANA_ENUM);
uRetCode = Netbios( &ncb );
if( uRetCode != NRC_GOODRET )
return uRetCode ;
for( int lana=0; lana<lana_enum.length; lana++ )
{
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = lana_enum.lana[lana];
uRetCode = Netbios( &ncb );
if( uRetCode == NRC_GOODRET )
break ;
}
if( uRetCode != NRC_GOODRET )
return uRetCode;
memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = lana_enum.lana[0];
strcpy( (char* )ncb.ncb_callname, "*" );
ncb.ncb_buffer = (unsigned char *) &Adapter;
ncb.ncb_length = sizeof(Adapter);
uRetCode = Netbios( &ncb );
if( uRetCode != NRC_GOODRET )
return uRetCode ;
sprintf(mac,"%02X-%02X-%02X-%02X-%02X-%02X",
Adapter.adapt.adapter_address[0],
Adapter.adapt.adapter_address[1],
Adapter.adapt.adapter_address[2],
Adapter.adapt.adapter_address[3],
Adapter.adapt.adapter_address[4],
Adapter.adapt.adapter_address[5] );
return 0;
}
//获取 cpu序列号
void GetSystemCpuId()
{
cout<<"获取CPU的";
system("wmic cpu get processorid ");
}
void GetCpuID(string& strCpuID)
{// CPU ID
BOOL bException = FALSE;
BYTE szCpu[32] = { 0 };
UINT uCpuID = 0U;
char szBuf[256] = {0};
UINT s1 = 0U;
UINT s2 = 0U;
__try
{
_asm
{
mov eax,01h
xor edx,edx
cpuid
mov s1,edx
mov s2,eax
}
sprintf(szBuf, "%08X%08X", s1, s2);
}
__except( EXCEPTION_EXECUTE_HANDLER )
{
bException = TRUE;
}
if( !bException )
{
strCpuID = szBuf;
}
}
//获取操作系统信息
void GetSystemVersion()
{
OSVERSIONINFO osInfo;
osInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
GetVersionEx(&osInfo);
if(osInfo.dwMajorVersion==5&&osInfo.dwMinorVersion==1)
{
printf("Microsoft Windows XP\n");
}
if(osInfo.dwMajorVersion==5&&osInfo.dwMinorVersion==0)
{
printf("Microsoft Windows 2000\n");
}
if(osInfo.dwMajorVersion<=4)
{
printf("Microsoft Windows NT\n ");
}
if(osInfo.dwMajorVersion==6&&osInfo.dwMinorVersion==0)
{
printf("Microsoft Windows vista\n");
}
if(osInfo.dwMajorVersion==6&&osInfo.dwMinorVersion==1)
{
printf("Microsoft Windows 7\n");
}
printf("The version of system is:%d.%d.%d\n",osInfo.dwMajorVersion,osInfo.dwMinorVersion,osInfo.dwBuildNumber);
//计算机名
char a[255]; unsigned long size=255;
GetComputerNameA(a,&size);
printf("The computer's name is:%s\n",a);
}
//获取.NetFrameWork版本信息
bool GetNetFrameWorkVersion()
{
bool frameWorkVersion=false;
char szFileName[][100]={{"C:\\Windows\\Microsoft.NET\\Framework\\v1.0.3705\\mscormmc.dll"},
{"C:\\Windows\\Microsoft.NET\\Framework\\v1.1.4322\\gacutil.exe.config"},
{"C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\aspnet_regbrowsers.exe"},
{"C:\\Windows\\Microsoft.NET\\Framework\\v3.0\\\WPF\\wpfgfx_v0300.dll"},
{"C:\\Windows\\Microsoft.NET\\Framework\\v3.5\\DataSvcUtil.exe"},
{"C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\AddInProcess32.exe"
}
};
char szDirName[][50]={{"%systemroot%\\Microsoft.NET\\Framework\\v1.0.3705"},
{"%systemroot%\\Microsoft.NET\\Framework\\v1.1.4322"},
{"%systemroot%\\Microsoft.NET\\Framework\\v2.0.50727"},
{"%systemroot%\\Microsoft.NET\\Framework\\v3.0"},
{"%systemroot%\\Microsoft.NET\\Framework\\v3.5"},
{"%systemroot%\\Microsoft.NET\\Framework\\v4.0.30319"
}
};
int i;
for(i=0;i<6;++i)
{
if(access(szFileName[i],0)==0)//判断文件是否存在
{
cout<<szDirName[i]<<"已经安装!"<<endl;
if(i==2)
{
frameWorkVersion=true;
}
}
else
{
cout<<szDirName[i]<<"未安装!"<<endl;
}
}
return frameWorkVersion;
}
//获取当前程序运行的路径
void GetCurrentProgramPath(char path[])
{
int fileLen=GetModuleFileName(NULL,path,1000);
int i=fileLen;
while(path[i]!='\\')
{
i--;
}
path[i+1]='\0';
}
//获取IE版本号 获取的是mshtml.dll文件的版本号,因为mshtml.dll版本号和ie的核心dll版本号相同。
bool GetIeVersion(LPTSTR lpIEversion , size_t cchLen)
{
const TCHAR szFilename[] = _T("mshtml.dll");
DWORD dwMajorVersion =0, dwMinorVersion = 0;
DWORD dwBuildNumber =0, dwRevisionNumber = 0;
DWORD dwHandle = 0;
TCHAR szBuf[80];
DWORD dwVerInfoSize = GetFileVersionInfoSize(szFilename, &dwHandle);
if (dwVerInfoSize)
{
LPVOID lpBuffer = LocalAlloc(LPTR, dwVerInfoSize);
if (lpBuffer)
{
if (GetFileVersionInfo(szFilename, dwHandle, dwVerInfoSize, lpBuffer))
{
VS_FIXEDFILEINFO * lpFixedFileInfo = NULL;
UINT nFixedFileInfoSize = 0;
if (VerQueryValue(lpBuffer,TEXT("\\"),(LPVOID*)&lpFixedFileInfo, &nFixedFileInfoSize) &&(nFixedFileInfoSize))
{
dwMajorVersion = HIWORD(lpFixedFileInfo->dwFileVersionMS);
dwMinorVersion = LOWORD(lpFixedFileInfo->dwFileVersionMS);
dwBuildNumber = HIWORD(lpFixedFileInfo->dwFileVersionLS);
dwRevisionNumber = LOWORD(lpFixedFileInfo->dwFileVersionLS);
}
}
LocalFree(lpBuffer);
}
}
else
return FALSE;
StringCchPrintf(szBuf,80, TEXT(" %d.%d.%d.%d") ,dwMajorVersion ,dwMinorVersion ,dwBuildNumber,dwRevisionNumber );
StringCchCat(lpIEversion ,cchLen,TEXT("Internet Explorer"));
StringCchCat(lpIEversion , cchLen , szBuf );
printf("ie版本为ie%d\n",dwMajorVersion);
if(dwMajorVersion==6)
{
return false;
}
return TRUE;
}
浙公网安备 33010602011771号