在.Net Framework 1.1下,如果采用Visual .Net 2003的打包程序,我们可以下载.Net 2003安装引导程序来帮助我们把.Net Framework和MDAC之类的打包进去。目前我没有找到.Net 2005的引导程序,很郁闷。采用.Net 2005做安装盘,最郁闷的地方在于,如果没有安装.Net Framework2.0,系统提醒安装,安装后,还需要再叫用户重新点安装程序进行安装。Boss说,必须傻瓜化地安装,不能叫用户点两次。更郁闷的是,程序用了MDAC2.8,在XP SP2后版本,会出现“严重错误”对话框,虽然不影响使用,但给用户体验很不好。怎么办?我只好用unmanaged的VC做了个检测程序(注册表检测)和运行需要的组件。这个程序没有考虑做成通用的,检测了.Net Framework2.0和MDAC 2.8,如果你觉得有用,你可以做成从配置文件里读取需要部署的组件,并自动运行部署。欢迎转载,但不允许删除如下网址:http://www.hzpal.com http://www.glassoo.com
代码如下:
欢迎转载,但不允许删除如下网址:http://www.hzpal.com http://www.glassoo.com
代码如下:
// 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