VC检测.net环境

#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <iostream>   

LPSTR regeditVision[] ={"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v2.0",
"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v2.0.50727",
"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v3.0",
"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v3.5"};

LPSTR sNetfile =   "C:\\Program Files\\NetMeeting\\conf.exe";   //.net安装包的路径
LPSTR sExefile   =   "C:\\Program Files\\Google\\Google Pinyin 2\\GooglePinyinSettingWizard.exe";//程序的路径    

using namespace std;
int CheckReg()
{   
    bool setup=TRUE;
    //判断注册表是否存在
    for (int i=0;i<4;i++)
    {
        HKEY ck;//注册表的键
        if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,regeditVision[i],0,KEY_ALL_ACCESS,&ck))//检查注册表是否存在这个键值 
        {       
            RegCloseKey(ck);//关闭注册表 
            setup=TRUE;
            break;
        }
        else  
        {  
            setup=FALSE;
        }
    }
    return setup;
}
int StartExe(LPSTR path)
{       
    STARTUPINFO stinfo;
    ZeroMemory((void*)&stinfo,   sizeof(STARTUPINFO));
    PROCESS_INFORMATION   ProcessInfo;
    stinfo.cb   =   sizeof(STARTUPINFO);
    stinfo.dwFlags   =   STARTF_USESHOWWINDOW;
    stinfo.wShowWindow   =   SW_SHOW;
    if(!CreateProcess(path,path,NULL,NULL,false,0,NULL,NULL,&stinfo,&ProcessInfo)) 
    {        
        MessageBox(NULL,"启动文件失败","提示",MB_OK);
        return 0;   
    }       
    else  
    {  
        //等待安装完成
        WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
        return 1;    
    }
}
int StartCheck()
{   
    if(CheckReg())  
    {
        if(IDYES==MessageBox(NULL,".net环境OK,是否安装你的安装包了","提示",MB_YESNO))
        {
            StartExe(sExefile); 
        }   
    }
    else  
    {       
        if(IDYES==MessageBox(NULL,"系统里没安装了.net,是否安装?","提示",MB_YESNO))
        {
            StartExe(sNetfile);
            StartCheck(); 
        }
    }   
    return 1;
}
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
    StartCheck();  
    return 0;
}

posted @ 2010-02-23 12:29  Yan Zhe  阅读(1434)  评论(3编辑  收藏  举报