C++检测windows操作系统.NET所有版本情况

 
#include  " stdafx.h "
#include <stdio.h>
#include <windows.h>
#include <time.h>
#include <iostream>
#include < string>
#include <wininet.h>
#include <sys\stat.h> 

#include <cstring>

#define MAXBLOCKSIZE 1024
using  namespace std;
#pragma comment( lib, "wininet.lib" )
#pragma comment(lib,"Version.lib") 
enum NetVersion{
    V_1_0= 0X1,
    V_2_0_SP1= 0X2,
    V_2_0= 0X4,
    V_3_0= 0X8,
    V_3_0_SP1= 0X10,
    V_4_0= 0x20,
    V_5_0= 0x40
};
char GetSystemDisk(){
     char str[ 255];   
    GetSystemDirectory(_T(str),  255);   
     return str[ 0];  
}

string ReadRegisteTable( const  char* root,LPCTSTR path, LPCTSTR key)
{
    HKEY hAppKey;
    LPCTSTR WINDS_SERVICE_REGISTRY_KEY=path;
    LPCTSTR DATA_FILE_SUB_KEY=key;
     char szDataFile[ 80];
     if( string(root)== string( " HKEY_LOCAL_MACHINE "))
    {
         long r=RegOpenKeyEx (
        HKEY_LOCAL_MACHINE,
        WINDS_SERVICE_REGISTRY_KEY,
         0,
        KEY_READ,
        &hAppKey);
         if (ERROR_SUCCESS ==r )
        {
            ULONG cbSize = MAX_PATH* sizeof(TCHAR);
            DWORD dwFlag = RegQueryValueEx (
            hAppKey,
            DATA_FILE_SUB_KEY,
            NULL,
            NULL,
            (LPBYTE)szDataFile,&cbSize);
            RegCloseKey (hAppKey);
             if (ERROR_SUCCESS == dwFlag)
            {
                 string strDate=szDataFile;  // MessageBox(strDate);
                  
                 return strDate;
            }
             return  "";
        }
    }
     if( string(root)== string( " HKEY_CURRENT_USER "))
    {
         if (ERROR_SUCCESS == RegOpenKeyEx (
        HKEY_CURRENT_USER,
        WINDS_SERVICE_REGISTRY_KEY,
         0,
        KEY_READ,
        &hAppKey))
        {
            ULONG cbSize = MAX_PATH* sizeof(TCHAR);
            DWORD dwFlag = RegQueryValueEx (
            hAppKey,
            DATA_FILE_SUB_KEY,
            NULL,
            NULL,
            (LPBYTE)szDataFile,&cbSize);
            RegCloseKey (hAppKey);
             if (ERROR_SUCCESS == dwFlag)
            {
                 string strDate=szDataFile;  // MessageBox(strDate);
                  
                 return strDate;
            }
             return  "";
        }
    }
     return  "";
}

void GetIEVersion(){
     
     char* path=( " SOFTWARE\\Microsoft\\Internet Explorer\\ ");
     string data=ReadRegisteTable( " HKEY_LOCAL_MACHINE ",path, " Version ");
    cout<< " IE版本: "<<data<<endl;

}

int GetNetAllVersions(){

    HKEY hKey;
    LPCTSTR path_V_1_0=TEXT( " SOFTWARE\\Microsoft\\.NETFramework\\v1.0 ");
    LPCTSTR path_V_2_0_SP1=TEXT( " SOFTWARE\\Microsoft\\.NETFramework\\v2.0 SP1 ");
    LPCTSTR path_V_2_0=TEXT( " SOFTWARE\\Microsoft\\.NETFramework\\v2.0.50727 ");
    LPCTSTR path_V_3_0=TEXT( " SOFTWARE\\Microsoft\\.NETFramework\\v3.0 ");
    LPCTSTR path_V_3_0_SP1=TEXT( " SOFTWARE\\Microsoft\\.NETFramework\\v3.0 SP1 ");
    LPCTSTR path_V_4_0=TEXT( " SOFTWARE\\Microsoft\\.NETFramework\\v4.0.30319 ");
    LONG rpath_V_1_0=RegOpenKeyEx(HKEY_LOCAL_MACHINE,path_V_1_0, 0,KEY_READ,&hKey);
    ::RegCloseKey(hKey);
    LONG rpath_V_2_0_SP1=RegOpenKeyEx(HKEY_LOCAL_MACHINE,path_V_2_0_SP1, 0,KEY_READ,&hKey);
    ::RegCloseKey(hKey);

    LONG rpath_V_2_0=RegOpenKeyEx(HKEY_LOCAL_MACHINE,path_V_2_0, 0,KEY_READ,&hKey);
    ::RegCloseKey(hKey);

    LONG rpath_V_3_0=RegOpenKeyEx(HKEY_LOCAL_MACHINE,path_V_3_0, 0,KEY_READ,&hKey);
    ::RegCloseKey(hKey);
    LONG rpath_V_3_0_SP1=RegOpenKeyEx(HKEY_LOCAL_MACHINE,path_V_3_0_SP1, 0,KEY_READ,&hKey);
    ::RegCloseKey(hKey);
    LONG rpath_V_4_0=RegOpenKeyEx(HKEY_LOCAL_MACHINE,path_V_4_0, 0,KEY_READ,&hKey);
    ::RegCloseKey(hKey);
     int result= 0;
     if(rpath_V_1_0==ERROR_SUCCESS){
        result=result|NetVersion::V_1_0;
        cout<< " 系统已经安装.NET:V_1_0 "<<endl;
    }
     if(rpath_V_2_0_SP1==ERROR_SUCCESS){
        result=result|NetVersion::V_2_0_SP1;
        cout<< " 系统已经安装.NET:V_2_0_SP1 "<<endl;
    }
     if(rpath_V_2_0==ERROR_SUCCESS){
        result=result|NetVersion::V_2_0;
        cout<< " 系统已经安装.NET:V_2_0 "<<endl;
    }
     if(rpath_V_3_0==ERROR_SUCCESS){
        result=result|NetVersion::V_3_0;
        cout<< " 系统已经安装.NET:V_3_0 "<<endl;
    }
     if(rpath_V_3_0_SP1==ERROR_SUCCESS){
        result=result|NetVersion::V_3_0_SP1;
        cout<< " 系统已经安装.NET:V_3_0_SP1 "<<endl;
    }
     if(rpath_V_4_0==ERROR_SUCCESS){
        result=result|NetVersion::V_4_0;
        cout<< " 系统已经安装.NET:V_4_0 "<<endl;
    }
     return result;
}

int main (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                     int nFunsterStil)
{
    GetIEVersion();
    GetNetAllVersions();
    
     char p=GetSystemDisk();
    cout<< " 系统盘为: "<<p<<endl;
     
     char a;
    cin>>a;
     return  1;
}

你可能感兴趣的:(windows)