代码如下:
// WCXSetup.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "WCXSetup.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
printf("警告:此窗口严禁手工关闭!如果您不小心关闭,请重新点安装程序!");
int nRetCode = 0;
if( NeedDotnetFramework() )
{
::StartExe("DOTNETFX.EXE");
}
if( NeedMDAC() )
{
::StartExe( "MDAC_TYP.EXE" );
}
return nRetCode;
}
void StartExe(const char* path)
{
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = path;
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
}
bool NeedMDAC()
{
HKEY hKey, hSub1key, hSub2key, hSub3key;
if (RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE", &hKey) == ERROR_SUCCESS)
{
if (RegOpenKey(hKey, "Classes", &hSub1key) == ERROR_SUCCESS)
{
if (RegOpenKey(hSub1key, "MDACVer.Version", &hSub2key) == ERROR_SUCCESS)
{
if (RegOpenKey(hSub2key, "CurVer", &hSub3key) == ERROR_SUCCESS)
{
char *szData;
DWORD dwType, dwLen;
szData = new char[101];
dwLen = 100;
if ( ::RegQueryValueEx(hSub3key, "", NULL, &dwType, (unsigned char *)szData, &dwLen ) == ERROR_SUCCESS )
{
::RegCloseKey( hSub3key );
if( strcmp( szData, "MDACVer.Version.2.8" ) > 0 )
{
return false;
}
}
else
{
::RegCloseKey( hSub3key );
}
}
::RegCloseKey( hSub2key );
}
::RegCloseKey( hSub1key );
}
::RegCloseKey( hKey );
}
return true;
}
bool NeedDotnetFramework()
{
HKEY hKey, hSub1key, hSub2key, hSub3key,hSub4key;
if (RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE", &hKey) == ERROR_SUCCESS)
{
if (RegOpenKey(hKey, "Microsoft", &hSub1key) == ERROR_SUCCESS)
{
if (RegOpenKey(hSub1key, ".NETFramework", &hSub2key) == ERROR_SUCCESS)
{
if (RegOpenKey(hSub2key, "policy", &hSub3key) == ERROR_SUCCESS)
{
if (RegOpenKey(hSub3key, "v2.0", &hSub4key) == ERROR_SUCCESS)
{
::RegCloseKey( hSub4key );
::RegCloseKey( hSub3key );
return false;
}
else
{
::RegCloseKey( hSub3key );
}
}
::RegCloseKey( hSub2key );
}
::RegCloseKey( hSub1key );
}
::RegCloseKey( hKey );
}
return true;
}
我不知道这个是不是最好的办法,请大家指点!听说Wise For .Net Installer 5.1版本支持.Net 程序的发布,不过没米:(//
#include "stdafx.h"
#include "WCXSetup.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
printf("警告:此窗口严禁手工关闭!如果您不小心关闭,请重新点安装程序!");
int nRetCode = 0;
if( NeedDotnetFramework() )
{
::StartExe("DOTNETFX.EXE");
}
if( NeedMDAC() )
{
::StartExe( "MDAC_TYP.EXE" );
}
return nRetCode;
}
void StartExe(const char* path)
{
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = path;
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
}
bool NeedMDAC()
{
HKEY hKey, hSub1key, hSub2key, hSub3key;
if (RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE", &hKey) == ERROR_SUCCESS)
{
if (RegOpenKey(hKey, "Classes", &hSub1key) == ERROR_SUCCESS)
{
if (RegOpenKey(hSub1key, "MDACVer.Version", &hSub2key) == ERROR_SUCCESS)
{
if (RegOpenKey(hSub2key, "CurVer", &hSub3key) == ERROR_SUCCESS)
{
char *szData;
DWORD dwType, dwLen;
szData = new char[101];
dwLen = 100;
if ( ::RegQueryValueEx(hSub3key, "", NULL, &dwType, (unsigned char *)szData, &dwLen ) == ERROR_SUCCESS )
{
::RegCloseKey( hSub3key );
if( strcmp( szData, "MDACVer.Version.2.8" ) > 0 )
{
return false;
}
}
else
{
::RegCloseKey( hSub3key );
}
}
::RegCloseKey( hSub2key );
}
::RegCloseKey( hSub1key );
}
::RegCloseKey( hKey );
}
return true;
}
bool NeedDotnetFramework()
{
HKEY hKey, hSub1key, hSub2key, hSub3key,hSub4key;
if (RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE", &hKey) == ERROR_SUCCESS)
{
if (RegOpenKey(hKey, "Microsoft", &hSub1key) == ERROR_SUCCESS)
{
if (RegOpenKey(hSub1key, ".NETFramework", &hSub2key) == ERROR_SUCCESS)
{
if (RegOpenKey(hSub2key, "policy", &hSub3key) == ERROR_SUCCESS)
{
if (RegOpenKey(hSub3key, "v2.0", &hSub4key) == ERROR_SUCCESS)
{
::RegCloseKey( hSub4key );
::RegCloseKey( hSub3key );
return false;
}
else
{
::RegCloseKey( hSub3key );
}
}
::RegCloseKey( hSub2key );
}
::RegCloseKey( hSub1key );
}
::RegCloseKey( hKey );
}
return true;
}
欢迎转载,但不允许删除如下网址:http://www.hzpal.com http://www.glassoo.com