vc 取windows系统信息 版本 cpu信息 内存信息 ie版本信息 office版本

头文件:
/*! Copyright (C)
*-------------------------------------------------------------------------------------------------
*
*    @file SystemInfo.h
*
*    @date 2009.9.15
*
*    @取系统环境、软件版本信息、上网环境等
*
*-------------------------------------------------------------------------------------------------
*/
#pragma once

#include "stdafx.h"

class CSystemInfo
{
public:
CString GetOSInfo();
CString GetMemInfo();
CString GetCPUModel();
CString GetIEInfo();
CString GetFirfoxInfo();
CString GetOfficeInfo();
};

功能实现
// vifo.cpp : 定义控制台应用程序的入口点。

#include "stdafx.h"
#include "SystemInfo.h"
#include <Atlbase.h>
#include<Windows.h>
#include<iostream>
using namespace std;


#define BUFSIZE                80
#define SM_SERVERR2         89

typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);

CString CSystemInfo::GetOSInfo()
{
CString strRet;

OSVERSIONINFOEX osvi;
BOOL bOsVersionInfoEx;
CString strTemp;
SYSTEM_INFO si;
PGNSI pGNSI;

ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
ZeroMemory(&si, sizeof(SYSTEM_INFO));

if(!(bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *)&osvi)))
{
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if(!GetVersionEx((OSVERSIONINFO *)&osvi))
{
return strRet;
}
}

switch(osvi.dwPlatformId)
{
case VER_PLATFORM_WIN32_NT:
//Windows NT

if((osvi.dwMajorVersion == 6) && (osvi.dwMinorVersion == 0))
{
if(osvi.wProductType == VER_NT_WORKSTATION)
{
strRet = _T("操作系统:                              Microsoft Windows Vista ");
}
}

if(osvi.dwMajorVersion == 5)
{
switch(osvi.dwMinorVersion)
{
case 0:
strRet = _T("操作系统:                              Microsoft Windows 2000 ");
break;
case 1:
strRet = _T("操作系统:                              Microsoft Windows XP ");
break;
case 2:
pGNSI = (PGNSI) GetProcAddress(
GetModuleHandle(_T("kernel32.dll")),
"GetNativeSystemInfo");
if(NULL != pGNSI)
pGNSI(&si);

if( GetSystemMetrics(SM_SERVERR2) )
strRet.Append(_T("Microsoft Windows Server 2003 \"R2\" "));
else if( osvi.wProductType == VER_NT_WORKSTATION &&
si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
{
strRet = _T("操作系统:                                  Microsoft Windows XP Professional x64 Edition ");
}
else strRet = _T("操作系统:                                 Microsoft Windows Server 2003, ");

break;
default:
break;
}
}

if(osvi.dwMajorVersion <= 4)
{
strRet = _T("操作系统:                                Microsoft Windows NT ");
}

if(bOsVersionInfoEx)
{
if ( osvi.wProductType == VER_NT_WORKSTATION &&
si.wProcessorArchitecture!=PROCESSOR_ARCHITECTURE_AMD64)
{
if( osvi.dwMajorVersion == 4 )
strRet.Append(_T("Workstation 4.0 "));
else if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
strRet.Append(_T("Home Edition "));
else strRet.Append(_T("Professional "));
}
else if ( osvi.wProductType == VER_NT_SERVER ||
osvi.wProductType == VER_NT_DOMAIN_CONTROLLER )
{
if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==2)
{
if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_IA64 )
{
if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
strRet.Append(_T("Datacenter Edition for Itanium-based Systems"));
else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
strRet.Append(_T("Enterprise Edition for Itanium-based Systems"));
}
else if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
{
if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
strRet.Append(_T("Datacenter x64 Edition "));
else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
strRet.Append(_T("Enterprise x64 Edition "));
else strRet.Append(_T("Standard x64 Edition "));
}
else
{
if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
strRet.Append(_T("Datacenter Edition "));
else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
strRet.Append(_T("Enterprise Edition "));
else if ( osvi.wSuiteMask == VER_SUITE_BLADE )
strRet.Append(_T("Web Edition "));
else strRet.Append(_T("Standard Edition "));
}
}
else if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==0)
{
if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
strRet.Append(_T("Datacenter Server "));
else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
strRet.Append(_T("Advanced Server "));
else strRet.Append(_T("Server "));
}
else // Windows NT 4.0
{
if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
strRet.Append(_T("Server 4.0, Enterprise Edition "));
else strRet.Append(_T("Server 4.0 "));
}
}       
}
else
{
HKEY hKey;
TCHAR szProductType[BUFSIZE];
DWORD dwBufLen = BUFSIZE;
LONG lRet;

lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
_T("SYSTEM\\CurrentControlSet\\Control\\ProductOptions"),
0, KEY_QUERY_VALUE, &hKey );
if( lRet != ERROR_SUCCESS )
return strRet;

lRet = RegQueryValueEx( hKey, _T("ProductType"), NULL, NULL,
(LPBYTE) szProductType, &dwBufLen);
RegCloseKey( hKey );

if( (lRet != ERROR_SUCCESS) || (dwBufLen > BUFSIZE) )
return strRet;

if ( lstrcmpi(_T("WINNT"), szProductType) == 0 )
strRet.Append(_T("Workstation "));
if ( lstrcmpi(_T("LANMANNT"), szProductType) == 0 )
strRet.Append(_T("Server "));
if ( lstrcmpi(_T("SERVERNT"), szProductType) == 0 )
strRet.Append(_T("Advanced Server "));

strTemp.Format(_T("%d.%d "), osvi.dwMajorVersion, osvi.dwMinorVersion);
strRet.Append(strTemp);   
}

if( osvi.dwMajorVersion == 4 &&
lstrcmpi( osvi.szCSDVersion, _T("Service Pack 6" )) == 0 )
{
HKEY hKey;
LONG lRet;

lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
_T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009"),
0, KEY_QUERY_VALUE, &hKey );
if( lRet == ERROR_SUCCESS )
{
strTemp.Format(_T("Service Pack 6a (Build %d) "), osvi.dwBuildNumber & 0xFFFF);
strRet.Append(strTemp);
}
else // Windows NT 4.0 prior to SP6a
{
strTemp.Format(_T("%s (Build %d) "), osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
strRet.Append(strTemp);
}

RegCloseKey( hKey );
}
else // not Windows NT 4.0
{
strTemp.Format(_T("%s (Build %d) "), osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
strRet.Append(strTemp);
}

break;
case VER_PLATFORM_WIN32_WINDOWS:
//Windows 9X
if(osvi.dwMajorVersion == 4)
{
switch(osvi.dwMinorVersion)
{
case 0:
strRet = _T("操作系统:                              Microsoft Windows 95 ");
if (osvi.szCSDVersion[1] == L'C' || osvi.szCSDVersion[1] == L'B')
strRet.Append(_T("OSR2 "));
break;
case 10:
strRet = _T("操作系统:                              Microsoft Windows 98 ");
if ( osvi.szCSDVersion[1] == L'A' || osvi.szCSDVersion[1] == L'B')
strRet.Append(_T("SE "));
break;
case 90:
strRet = _T("操作系统:                              Microsoft Windows Me ");
break;
default:
break;
}
}

break;
case VER_PLATFORM_WIN32s:
break;
default:
break;
}
strRet.Append(_T("\n"));
return strRet;
}

CString CSystemInfo::GetCPUModel()
{
CString strRet;

CRegKey regKey;
TCHAR szModel[200];
DWORD dwLen = 200;
if(regKey.Open(HKEY_LOCAL_MACHINE, _T("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"), KEY_QUERY_VALUE) == ERROR_SUCCESS)
{
if(regKey.QueryStringValue(_T("ProcessorNameString"), szModel, &dwLen) == ERROR_SUCCESS)
{
strRet = _T("\n\n\n\n\n\n以下为用户系统信息:\n处理器(CPU):                      ");
strRet.Append(szModel);
strRet.Append(_T("\n"));
}
else
{
dwLen = 200;
if(regKey.QueryStringValue(_T("Identifier"), szModel, &dwLen) == ERROR_SUCCESS)
{
strRet = _T("\n处理器(CPU)                      ");
strRet.Append(szModel);
strRet.Append(_T("\n"));
}
}
}
return strRet;

}

CString CSystemInfo::GetMemInfo()
{
CString strRet;

TCHAR szSize[100];
MEMORYSTATUS ms;
GlobalMemoryStatus(&ms);

if(StrFormatByteSize(ms.dwTotalPhys, szSize, 100) != NULL)
{
strRet=(_T("物理内存:                              "));
strRet.Append(szSize);
strRet.Append(_T("\n"));
}
return strRet;

}

CString CSystemInfo::GetIEInfo()
{
CString strRet;
CString str;
CString strr;
CString stf;
CString stff;
CRegKey regKey;
TCHAR szVer[200];
DWORD dwLen = 200;

if(regKey.Open(HKEY_CLASSES_ROOT, _T("http\\shell\\open\\command"), KEY_QUERY_VALUE) == ERROR_SUCCESS)
{
if(regKey.QueryStringValue(_T(""), szVer, &dwLen) == ERROR_SUCCESS)
{  
str = "Internet Explorer";
strr.Format(_T("%s"),szVer);
int index = strr.Find(str);

if(index >= 0)
{   
strRet = _T("默认浏览器:                           Internet Explorer\n");
}


stf = "Mozilla Firefox";
stff.Format(_T("%s"),szVer);
index = stff.Find(stf);
if(index >= 0)
{
strRet = _T("默认浏览器:                          Mozilla Firefox\n");
}

}
}

if(regKey.Open(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Internet Explorer"), KEY_QUERY_VALUE) == ERROR_SUCCESS)
{
if(regKey.QueryStringValue(_T("Version"), szVer, &dwLen) == ERROR_SUCCESS)
{
strRet.Append(_T("IE 版本                                  "));
strRet.Append(_T("Internet Explorer V"));
strRet.Append(szVer);
strRet.Append(_T("\n"));
}
}

return strRet;

}
CString CSystemInfo::GetFirfoxInfo()
{
CString strRet;
CRegKey regKey;
TCHAR szVer[200];
DWORD dwLen = 200;
if(regKey.Open(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Mozilla\\Mozilla Firefox"), KEY_QUERY_VALUE) == ERROR_SUCCESS)
{     
if(regKey.QueryStringValue(_T("CurrentVersion"), szVer, &dwLen) == ERROR_SUCCESS)
{
strRet = _T("Firefox 版本:                         ");
strRet.Append(szVer);
strRet.Append(_T("\n"));
}
}
return strRet;   

}
CString CSystemInfo::GetOfficeInfo()
{
CString strRet;
CString strW;
CString strO;
CRegKey regKey;

TCHAR szVer[200];
TCHAR szW[200];
DWORD dwLen = 200;
int v;
int p;

for(v = 8;v <= 12;v++)//Mircrosoft office 8.0-----12.0
{
HKEY hOffice;
DWORD dwValue,dwLength,dwType = REG_SZ;

strRet.Format(_T("SOFTWARE\\Microsoft\\Office\\%d.0\\Common\\InstallRoot"),v);
dwValue = RegOpenKeyExW(HKEY_LOCAL_MACHINE,strRet,0,KEY_READ,&hOffice);

if (dwValue != ERROR_SUCCESS)
{
continue;
}

dwLength = 0;
dwValue = RegQueryValueEx(hOffice, _T("Path"),0, &dwType,NULL, &dwLength); //Mircrosoft office 路径是否存在,如不存在返回继续循环

if ( dwValue != ERROR_SUCCESS || dwLength <= 0)
{
RegCloseKey(hOffice);
continue;
}

strRet.Format(_T("SOFTWARE\\Microsoft\\Office\\%d.0\\Common\\ProductVersion"), v);
if (regKey.Open(HKEY_LOCAL_MACHINE, strRet, KEY_QUERY_VALUE) == ERROR_SUCCESS)
{
if(regKey.QueryStringValue(_T("LastProduct"),szVer,&dwLen) == ERROR_SUCCESS)//取office 版本号
{
strRet = _T("Microsoft Office 版本:         ");
strRet.Append(szVer);
strRet.Append(_T("\n"));
break;
}
}
}

for(v = 1;v <= 6;v++)                                               //金山 WPS office版本1.0-------6.0
{
HKEY hOffice;
DWORD dwLength,dwValue,dwType = REG_SZ;
strW.Format(_T("SOFTWARE\\Kingsoft\\Office\\%d.0\\common"), v);
dwValue = RegOpenKeyExW(HKEY_LOCAL_MACHINE, strW, 0,KEY_READ,&hOffice);

if(dwValue != ERROR_SUCCESS)
{
continue;
}

dwLength = 0;
dwValue = RegQueryValueEx(hOffice, _T("InstallRoot"), 0,&dwType, NULL, &dwLength);//office 路径是否存在,如不存在返回继续循环
if(dwValue != ERROR_SUCCESS || dwLength <= 0)
{
RegCloseKey(hOffice);
continue;
}
strW.Format(_T("SOFTWARE\\Kingsoft\\Office\\%d.0\\common"), v);
if (regKey.Open(HKEY_LOCAL_MACHINE, strW, KEY_QUERY_VALUE) == ERROR_SUCCESS)
{
if(regKey.QueryStringValue(_T("Version"),szW,&dwLen) == ERROR_SUCCESS)//取WPS版本号
{
strRet.Append(_T("WPS Office 版本:                  "));
strRet.Append(szW);
strRet.Append(_T("\n"));
}
}
}

for(v = 1;v<=3;v++ )                                                          //openoffice
{
for(p = 0;p<10;p++)
{
HKEY hOffice;
DWORD dwValue,dwLength,dwType = REG_SZ;

strO.Format(_T("SOFTWARE\\OpenOffice.org\\OpenOffice.org\\%d.%d"), v, p);
dwValue = RegOpenKeyExW(HKEY_LOCAL_MACHINE,strO,0,KEY_READ,&hOffice);

if (dwValue != ERROR_SUCCESS)
{
continue;
}

dwLength = 0;
dwValue = RegQueryValueEx(hOffice, _T("Path"),0, &dwType,NULL, &dwLength); //office 路径是否存在,如不存在返回继续循环

if ( dwValue != ERROR_SUCCESS || dwLength <= 0)
{
RegCloseKey(hOffice);
continue;

}
strO.Format(_T("%d.%d"), v,p);
strRet.Append(_T("Openoffice 版本:                  OpenOffice.org "));
strRet.Append(strO);           
}
}
return strRet;
}


功能显示
#include "stdafx.h"
#include "SystemInfo.h"
#include <fstream>
#include<iostream>
using namespace std;

int __cdecl _tmain()
{
CSystemInfo s;
s.GetOSInfo();
s.GetCPUModel();
s.GetMemInfo();
s.GetIEInfo();
s.GetOfficeInfo();
//wcout

_tprintf( TEXT("\n%s\n"), s.GetOSInfo() );
_tprintf( TEXT("\n%s\n"), s.GetCPUModel() );
_tprintf( TEXT("\n%s\n"), s.GetMemInfo() );
_tprintf( TEXT("\n%s\n"), s.GetIEInfo() );
_tprintf( TEXT("\n%s\n"), s.GetOfficeInfo() );

CFile   cf;  
CString   strPath;  
strPath="ta.text";//记事本路径。比如e:/ta.txt;也可以使用相对路径。  
cf.Open(strPath,CFile::modeCreate   |   CFile::modeWrite,NULL);//打开文件,此文件如果不存在,就给它再创个。  
//CString   a="\n";//假设a为输入的字串
//cf.Write(a,a.GetLength());
cf.Write(s.GetOSInfo(),s.GetOSInfo().GetLength()*2);
//cf.Write(a,a.GetLength());
cf.Write(s.GetCPUModel(),s.GetCPUModel().GetLength()*2);//写入到文件中。
cf.Write(s.GetMemInfo(),s.GetMemInfo().GetLength()*2);
cf.Write(s.GetIEInfo(),s.GetIEInfo().GetLength()*2);
cf.Write(s.GetOfficeInfo(),s.GetOfficeInfo().GetLength()*2);
cf.Close();//记得退出时,要关掉文件

}
posted @ 2016-04-07 12:07  恋恋西风  阅读(205)  评论(0编辑  收藏  举报