头文件:

/*! 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();//记得退出时,要关掉文件



}

vc 取windows系统信息 版本 cpu信息 内存信息 ie版本信息 office版本的更多相关文章

  1. Linux 简单命令查询CPU、内存、网卡等信息

    [转自]Linux查询CPU.内存.网卡等信息 看CPU信息(型号)# cat /proc/cpuinfo | grep name | cut -f2 -d: |uniq -c      1  Int ...

  2. Linux查看系统信息(操作系统版本,进程,任务,CPU,内存,磁盘等信息)

    查看操作系统: cat /proc/version   # 内核版本 cat /etc/issue   # 发行版本 head -n 1 /etc/issue uname -a lsb_release ...

  3. sql server 运维时CPU,内存,操作系统等信息查询(用sql语句)

    我们只要用到数据库,一般会遇到数据库运维方面的事情,需要我们寻找原因,有很多是关乎处理器(CPU).内存(Memory).磁盘(Disk)以及操作系统的,这时我们就需要查询他们的一些设置和内容,下面讲 ...

  4. 『开发技术』Ubuntu与Windows如何查看CPU&GPU&内存占用量

    0 序·简介 在使用Ubuntu或者Windows执行一些复杂数据运算时,需要关注下CPU.GPU以及内存占用量,如果数据运算超出了负荷,会产生难以预测的错误.本文将演示如何用简单地方式,实时监控Ub ...

  5. windows 10占用cpu和内存过高

    自从安装了windows 10,开机之后cpu和内存一直占用很高,尤其是system进程,一直占cpu在13%左右,上网查到一个解决方式,如下: cpu瞬间变为1%

  6. python利用WMI监控windows状态如CPU、内存、硬盘

    安装pywin32库 下载地址: https://sourceforge.net/projects/pywin32/files%2Fpywin32/选择对应python版本的文件.下载后在window ...

  7. 获取系统信息(CPU、内存等)

    简述 获取计算机CPU.主板.内存.硬盘.网卡这些信息,Qt中没有相应的处理,所以需要根据平台来做差异化处理.也许Qt为了跨平台,没有提供与操作系统和硬件密切相关的一些功能(如内存.CPU.硬盘等相关 ...

  8. Ubuntu下查看CPU、内存和硬盘详细信息的几个命令

    CPU: 型号:grep "model name" /proc/cpuinfo |awk -F ':' '{print $NF}' 数量:lscpu |grep "CPU ...

  9. Ubuntu16下查看CPU、内存和磁盘相关信息

    1.内存 查看内存#free -m total used free shared buff/cache available Mem: Swap: 2.CPU 查看逻辑cpu个数: #cat /proc ...

随机推荐

  1. OpenSSL进行SSL通讯的一些问题

    这两个星期真是被OpenSSL给烦透了,几个很简单基本的问题(如果没人告诉你真的很难测出来)把我搞的..哎,有时候真是不知道自己该不该搞技术,发现自己头脑真是蠢得很... 直接上正题. 第一个问题: ...

  2. 【转】Linux 的启动流程

    半年前,我写了<计算机是如何启动的?>,探讨BIOS和主引导记录的作用. 那篇文章不涉及操作系统,只与主板的板载程序有关.今天,我想接着往下写,探讨操作系统接管硬件以后发生的事情,也就是操 ...

  3. Redis在Windows环境下搭建

    1.  下载Redis-Windows版本 Redis官网下载页面: http://redis.io/download Windows下Redis项目: https://github.com/MSOp ...

  4. bzoj1760 [Baltic2009]Triangulation

    给定一个多边形的三角剖分(n<=1e5),且每个三角形有其颜色,问最多可以把这个三角剖分分成几个联通的部分,使任何一种颜色不出现在多个连通块中 建出三角剖分对应的树,同种颜色的点之间的路径是不能 ...

  5. 【solr】solr5.0整合中文分词器

    1.solr自带的分词器远远满足不了中文分词的需求,经查使用最多的分词器是solr是mmseg4j分词器,具体整合大家可以参考 https://github.com/zhuomingliang/mms ...

  6. 黄聪:wordpress工作原理

    WP初始化的过程:当你输入<yourlink>/wordpress对wordpress进行初始化时,wordpress默认会找根目录下的index.php页面,看一下index.php页面 ...

  7. Redis作者谈Redis应用场景(转)

    毫无疑问,Redis开创了一种新的数据存储思路,使用Redis,我们不用在面对功能单调的数据库时,把精力放在如何把大象放进冰箱这样的问题上,而是利用Redis灵活多变的数据结构和数据操作,为不同的大象 ...

  8. 1.运行Android Studio,一直提示:Error running app: Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled.

    1.解决问题办法:菜单栏,Tools -> Adnroid -> enable ADB integration勾上 2.暂时性的解决方案:在Android Studio中的:Prefere ...

  9. mysql 正则

    mysql 正则学习 基本字符匹配 select desk from dealer_info where desk regexp "82107777"; . 表示匹配任意一个字符 ...

  10. REST架构实质(转)

    REST(Representational State Transfer) 曾经被误解为只是CRUD(增删改查),从这个层面上,好像REST只是和RPC一个层面的东西,没有什么了不起,其实这些都是对R ...