以下以 .net 系统为例:
1. 判断 IIS 的版本号
var int nMaxFrameVer;
g_IISVer = Install.GetAppVer("IIS");
if( g_IISVer < 5 )
{
MessageBox("请先安装 IIS");
Install.CancelInstall();
return;
}
2. 判断 Framework 的版本号
g_frameWorkVer = Install.GetAppVer("Framework");
nMaxFrameVer = g_frameWorkVer.Left(g_frameWorkVer.Find("."));
if (nMaxFrameVer<2)
{
MessageBox(Error_FrameWork) ;
Install.CancelInstall();
return ;
}
3. 因为当前BS 应用需要连接数据库,所以在安装过程中需要输入数据库信息, 以下以 SqlServer 为例。
DlgParam.SetValue("Prompt" , "设置数据库");
DlgParam.SetValue("ItemCount" ,4 );
DlgParam.SetValue("Item1_Prompt" , "数据库服务器:" );
DlgParam.SetValue("Item2_Prompt" , 数据库名称:");
DlgParam.SetValue("Item3_Prompt" , 登录名:");
DlgParam.SetValue("Item4_Prompt" , "密 码:");
DlgParam.SetValue("Item1_Data", g_DBServer );
DlgParam.SetValue("Item2_Data", g_DBName );
DlgParam.SetValue("Item3_Data", g_DBUser );
DlgParam.SetValue("Item4_Style", 4 ,g_dbPwd);
nOpType = Install.DoDialog( "SdEdit" , DlgParam );
g_DBServer = DlgParam.GetValue("Item1_Data");
g_DBName = DlgParam.GetValue("Item2_Data");
g_DBUser = DlgParam.GetValue("Item3_Data");
g_DBPwd = DlgParam.GetValue("Item4_Data");
DataCmpGoto( nOpType , OT_CANCEL ,"Cancel" );
DataCmpGoto( nOpType , OT_BREAK ,"SdSetDestPath" );
// 调用 VBScript 判断当前连接是否成功,成功的话就返回连接字符串
g_dbConnStr = CallVBSFunction("GetSQLConnStr",g_DBServer,g_DBName,g_DBUser,g_DBPwd );
if(g_dbConnStr == "" )
{
MessageBox(Error_DataBaseConnStr) ;
Goto SetDataBase;
}
4. 在安装完成后创建Web虚拟目录
strTargetDir = Install.GetPath( "PATH_S_TARGETDIR" );
// 调用 VBScript 创建Web虚拟目录
// 只在第一次安装时才创建虚拟目录,更新安装不做任务操作
if( Install.GetSetupMode() == SM_FINSTALL )
{
//修改WEB.CONFIG
CallVBSFunction("WriteConfigXml",strTargetDir + "//Web.Config" ,"Connstring",g_dbConnStr) ;
//重新注册IIS
DlgParam.SetValue("Prompt" ,Text_RegIIS);
Install.ShowWaitingDlg( DlgParam );
strRegIISCmd = GetFrameWorkDir() + "aspnet_regiis.exe -i" ;
//Install.ExecConsoleCmd( strRegIISCmd , 1 );
// 设置 IIS 的一些属性,开放一些权限
CallVBSFunction("SetIISInfo",g_frameWorkVer) ;
Install.CloseWaitingDlg();
//创建Web虚拟目录
DlgParam.SetValue("Prompt" ,Text_CreateVirtualDir);
nstall.ShowWaitingDlg( DlgParam );
CallVBSFunction( "CreateVirtualDir" , g_virtualDir , strTargetDir , "default.aspx" );
Install.CloseWaitingDlg();
}
5. 在安装完成后打开一个默认的页面
if( Install.GetSetupMode() == SM_GENERAL )
{
strSetURL = "http://127.0.0.1/" + g_virtualDir + "/ public/login.aspx” ;
ShellExec( strSetURL );
}
6. End
完整的例子:
var CValueSet DlgParam;
var double g_IISVer;
var string g_frameWorkVer ;
var string g_virtualDir;
var string g_dbServer;
var string g_dbName;
var string g_dbUser;
var string g_dbPwd;
var string g_dbConnStr;
var int nOpType;
////////////////////////////////////////////////////////////////////////////////
//定义界面文字
var string Error_IIS ;
var string Error_FrameWork ;
var string Error_VirtualDirCreate ;
var string Error_DataBaseConnStr ;
var string Text_CreateVirtualDir ;
var string Text_RegIIS ;
var string Label_DataBase_Title ;
var string Label_DataBase_Server ;
var string Label_DataBase_Name ;
var string Label_DataBase_User ;
var string Label_DataBase_Pwd ;
var string RunPage ;
////////////////////////////////////////////////////////////////////////////////
function void InitData()
{
Error_IIS = "请先安装 IIS" ;
Error_FrameWork = "FrameWork版本至少为2.0或更高版本" ;
Error_VirtualDirCreate = "虚拟目录创建失败" ;
Error_DataBaseConnStr = "数据库连接错误" ;
Text_CreateVirtualDir = "正在创建虚拟目录..." ;
Text_RegIIS = "正在更新 ASP.NET 应用程序的脚本映射..." ;
Label_DataBase_Title = "设置数据库" ;
Label_DataBase_Server = "数据库服务器:" ;
Label_DataBase_Name = "数据库名称:" ;
Label_DataBase_User = "登录名:" ;
Label_DataBase_Pwd = "密 码:" ;
RunPage = "public/login.aspx" ;
g_virtualDir = "DocGuarder";
g_dbServer = "127.0.0.1" ;
g_dbName = "DocGuarder" ;
g_dbUser = "sa" ;
g_dbPwd = "" ;
}
function void OnBegin()
{
InitData() ;
var int nMaxFrameVer;
g_IISVer = Install.GetAppVer("IIS");
if( g_IISVer < 5 )
{
MessageBox(Error_IIS);
Install.CancelInstall();
return;
}
g_frameWorkVer = Install.GetAppVer("Framework");
nMaxFrameVer = g_frameWorkVer.Left(g_frameWorkVer.Find("."));
if (nMaxFrameVer<2)
{
MessageBox(Error_FrameWork) ;
Install.CancelInstall();
return ;
}
if( Install.IsInstalled() == 0 )
FirstInstall();
else
UpdateInstall();
}
function void FirstInstall()
{
SdWelcome:
nOpType = Install.DoDialog( "SdWelcome" );
DataCmpGoto( nOpType , OT_CANCEL ,"Cancel" );
SdSetDestPath:
nOpType = Install.DoDialog( "SdSetDestPath" );
DataCmpGoto( nOpType , OT_CANCEL ,"Cancel" );
DataCmpGoto( nOpType , OT_BREAK ,"SdWelcome" );
SetDataBase:
DlgParam.SetValue("Prompt" , "设置数据库");
DlgParam.SetValue("ItemCount" ,4 );
DlgParam.SetValue("Item1_Prompt" , "数据库服务器:" );
DlgParam.SetValue("Item2_Prompt" , 数据库名称:");
DlgParam.SetValue("Item3_Prompt" , 登录名:");
DlgParam.SetValue("Item4_Prompt" , "密 码:");
DlgParam.SetValue("Item1_Data", g_DBServer );
DlgParam.SetValue("Item2_Data", g_DBName );
DlgParam.SetValue("Item3_Data", g_DBUser );
DlgParam.SetValue("Item4_Style", 4 ,g_dbPwd);
nOpType = Install.DoDialog( "SdEdit" , DlgParam );
g_DBServer = DlgParam.GetValue("Item1_Data");
g_DBName = DlgParam.GetValue("Item2_Data");
g_DBUser = DlgParam.GetValue("Item3_Data");
g_DBPwd = DlgParam.GetValue("Item4_Data");
DataCmpGoto( nOpType , OT_CANCEL ,"Cancel" );
DataCmpGoto( nOpType , OT_BREAK ,"SdSetDestPath" );
// 调用 VBScript 判断当前连接是否成功,成功的话就返回连接字符串
g_dbConnStr = CallVBSFunction("GetSQLConnStr",g_DBServer,g_DBName,g_DBUser,g_DBPwd );
if(g_dbConnStr == "" )
{
MessageBox(Error_DataBaseConnStr) ;
Goto SetDataBase;
}
Cancel:
}
function void UpdateInstall()
{
Install.DoDialog( "SdSetUpdateMode" );
}
function void OnProcess()
{
Install.SetVarTabValue( "VirtualDir" ,g_virtualDir );
var string strRegIISCmd,strTargetDir ;
Install.DoDialog( "SdProcess" );
DataCmpGoto( nOpType , OT_CANCEL ,"Cancel" );
DataCmpGoto( nOpType , OT_REBOOTDO ,"RebootInstall" );
strTargetDir = Install.GetPath( "PATH_S_TARGETDIR" );
// 调用 VBScript 创建Web虚拟目录
if( Install.GetSetupMode() == SM_FINSTALL)
{
//修改WEB.CONFIG
CallVBSFunction("WriteConfigXml",strTargetDir + "//Web.Config" ,"Connstring",g_dbConnStr) ;
//重新注册IIS
DlgParam.SetValue("Prompt" ,Text_RegIIS);
Install.ShowWaitingDlg( DlgParam );
strRegIISCmd = GetFrameWorkDir() + "aspnet_regiis.exe -i" ;
//Install.ExecConsoleCmd( strRegIISCmd , 1 );
CallVBSFunction("SetIISInfo",g_frameWorkVer) ;
Install.CloseWaitingDlg();
DlgParam.SetValue("Prompt" ,Text_CreateVirtualDir);
Install.ShowWaitingDlg( DlgParam );
CallVBSFunction( "CreateVirtualDir" , g_virtualDir , strTargetDir , "default.aspx" );
Install.CloseWaitingDlg();
}
return;
RebootInstall:
Cancel:
}
function void OnEnd()
{
var string strSetURL;
if( Install.GetSetupState() == SS_INSTALL )
{
Install.DoDialog( "SdFinish" );
if( Install.GetSetupMode() == SM_FINSTALL )
{
strSetURL = "http://127.0.0.1/" + g_virtualDir + "/" + RunPage ;
ShellExec( strSetURL );
}
}
else if( Install.GetSetupState() == SS_INSTALL_REBOOTDO )
Install.DoDialog( "SdRebootDo" );
}
//===================================
// 在反安装时执行的脚本
//===================================
function void OnUninstallBegin()
{
g_virtualDir = RegKey.GetRegStrValue( "HKEY_LOCAL_MACHINE" , "SOFTWARE//HuatuSoft//DocGuarder" , "VirtualDir" , "" );
CallVBSFunction("DeleteVirtualDir", g_virtualDir) ;
Uninstall.Uninstall();
}
function string GetFrameWorkDir()
{
var string strWinPath;
var string strPath;
var string strFrameWorkVer;
// 得到framework 版本号
strFrameWorkVer = Install.GetAppVer("Framework");
//得到WINDOWS目录
strWinPath = Install.GetPath("PATH_S_WIN");
//得到FRAMEWORK目录
strPath = strWinPath + "//Microsoft.NET//Framework//V" + strFrameWorkVer + "//";
return strPath;
}
1. 判断 IIS 的版本号
var int nMaxFrameVer;
g_IISVer = Install.GetAppVer("IIS");
if( g_IISVer < 5 )
{
MessageBox("请先安装 IIS");
Install.CancelInstall();
return;
}
2. 判断 Framework 的版本号
g_frameWorkVer = Install.GetAppVer("Framework");
nMaxFrameVer = g_frameWorkVer.Left(g_frameWorkVer.Find("."));
if (nMaxFrameVer<2)
{
MessageBox(Error_FrameWork) ;
Install.CancelInstall();
return ;
}
3. 因为当前BS 应用需要连接数据库,所以在安装过程中需要输入数据库信息, 以下以 SqlServer 为例。
DlgParam.SetValue("Prompt" , "设置数据库");
DlgParam.SetValue("ItemCount" ,4 );
DlgParam.SetValue("Item1_Prompt" , "数据库服务器:" );
DlgParam.SetValue("Item2_Prompt" , 数据库名称:");
DlgParam.SetValue("Item3_Prompt" , 登录名:");
DlgParam.SetValue("Item4_Prompt" , "密 码:");
DlgParam.SetValue("Item1_Data", g_DBServer );
DlgParam.SetValue("Item2_Data", g_DBName );
DlgParam.SetValue("Item3_Data", g_DBUser );
DlgParam.SetValue("Item4_Style", 4 ,g_dbPwd);
nOpType = Install.DoDialog( "SdEdit" , DlgParam );
g_DBServer = DlgParam.GetValue("Item1_Data");
g_DBName = DlgParam.GetValue("Item2_Data");
g_DBUser = DlgParam.GetValue("Item3_Data");
g_DBPwd = DlgParam.GetValue("Item4_Data");
DataCmpGoto( nOpType , OT_CANCEL ,"Cancel" );
DataCmpGoto( nOpType , OT_BREAK ,"SdSetDestPath" );
// 调用 VBScript 判断当前连接是否成功,成功的话就返回连接字符串
g_dbConnStr = CallVBSFunction("GetSQLConnStr",g_DBServer,g_DBName,g_DBUser,g_DBPwd );
if(g_dbConnStr == "" )
{
MessageBox(Error_DataBaseConnStr) ;
Goto SetDataBase;
}
4. 在安装完成后创建Web虚拟目录
strTargetDir = Install.GetPath( "PATH_S_TARGETDIR" );
// 调用 VBScript 创建Web虚拟目录
// 只在第一次安装时才创建虚拟目录,更新安装不做任务操作
if( Install.GetSetupMode() == SM_FINSTALL )
{
//修改WEB.CONFIG
CallVBSFunction("WriteConfigXml",strTargetDir + "//Web.Config" ,"Connstring",g_dbConnStr) ;
//重新注册IIS
DlgParam.SetValue("Prompt" ,Text_RegIIS);
Install.ShowWaitingDlg( DlgParam );
strRegIISCmd = GetFrameWorkDir() + "aspnet_regiis.exe -i" ;
//Install.ExecConsoleCmd( strRegIISCmd , 1 );
// 设置 IIS 的一些属性,开放一些权限
CallVBSFunction("SetIISInfo",g_frameWorkVer) ;
Install.CloseWaitingDlg();
//创建Web虚拟目录
DlgParam.SetValue("Prompt" ,Text_CreateVirtualDir);
nstall.ShowWaitingDlg( DlgParam );
CallVBSFunction( "CreateVirtualDir" , g_virtualDir , strTargetDir , "default.aspx" );
Install.CloseWaitingDlg();
}
5. 在安装完成后打开一个默认的页面
if( Install.GetSetupMode() == SM_GENERAL )
{
strSetURL = "http://127.0.0.1/" + g_virtualDir + "/ public/login.aspx” ;
ShellExec( strSetURL );
}
6. End
完整的例子:
var CValueSet DlgParam;
var double g_IISVer;
var string g_frameWorkVer ;
var string g_virtualDir;
var string g_dbServer;
var string g_dbName;
var string g_dbUser;
var string g_dbPwd;
var string g_dbConnStr;
var int nOpType;
////////////////////////////////////////////////////////////////////////////////
//定义界面文字
var string Error_IIS ;
var string Error_FrameWork ;
var string Error_VirtualDirCreate ;
var string Error_DataBaseConnStr ;
var string Text_CreateVirtualDir ;
var string Text_RegIIS ;
var string Label_DataBase_Title ;
var string Label_DataBase_Server ;
var string Label_DataBase_Name ;
var string Label_DataBase_User ;
var string Label_DataBase_Pwd ;
var string RunPage ;
////////////////////////////////////////////////////////////////////////////////
function void InitData()
{
Error_IIS = "请先安装 IIS" ;
Error_FrameWork = "FrameWork版本至少为2.0或更高版本" ;
Error_VirtualDirCreate = "虚拟目录创建失败" ;
Error_DataBaseConnStr = "数据库连接错误" ;
Text_CreateVirtualDir = "正在创建虚拟目录..." ;
Text_RegIIS = "正在更新 ASP.NET 应用程序的脚本映射..." ;
Label_DataBase_Title = "设置数据库" ;
Label_DataBase_Server = "数据库服务器:" ;
Label_DataBase_Name = "数据库名称:" ;
Label_DataBase_User = "登录名:" ;
Label_DataBase_Pwd = "密 码:" ;
RunPage = "public/login.aspx" ;
g_virtualDir = "DocGuarder";
g_dbServer = "127.0.0.1" ;
g_dbName = "DocGuarder" ;
g_dbUser = "sa" ;
g_dbPwd = "" ;
}
function void OnBegin()
{
InitData() ;
var int nMaxFrameVer;
g_IISVer = Install.GetAppVer("IIS");
if( g_IISVer < 5 )
{
MessageBox(Error_IIS);
Install.CancelInstall();
return;
}
g_frameWorkVer = Install.GetAppVer("Framework");
nMaxFrameVer = g_frameWorkVer.Left(g_frameWorkVer.Find("."));
if (nMaxFrameVer<2)
{
MessageBox(Error_FrameWork) ;
Install.CancelInstall();
return ;
}
if( Install.IsInstalled() == 0 )
FirstInstall();
else
UpdateInstall();
}
function void FirstInstall()
{
SdWelcome:
nOpType = Install.DoDialog( "SdWelcome" );
DataCmpGoto( nOpType , OT_CANCEL ,"Cancel" );
SdSetDestPath:
nOpType = Install.DoDialog( "SdSetDestPath" );
DataCmpGoto( nOpType , OT_CANCEL ,"Cancel" );
DataCmpGoto( nOpType , OT_BREAK ,"SdWelcome" );
SetDataBase:
DlgParam.SetValue("Prompt" , "设置数据库");
DlgParam.SetValue("ItemCount" ,4 );
DlgParam.SetValue("Item1_Prompt" , "数据库服务器:" );
DlgParam.SetValue("Item2_Prompt" , 数据库名称:");
DlgParam.SetValue("Item3_Prompt" , 登录名:");
DlgParam.SetValue("Item4_Prompt" , "密 码:");
DlgParam.SetValue("Item1_Data", g_DBServer );
DlgParam.SetValue("Item2_Data", g_DBName );
DlgParam.SetValue("Item3_Data", g_DBUser );
DlgParam.SetValue("Item4_Style", 4 ,g_dbPwd);
nOpType = Install.DoDialog( "SdEdit" , DlgParam );
g_DBServer = DlgParam.GetValue("Item1_Data");
g_DBName = DlgParam.GetValue("Item2_Data");
g_DBUser = DlgParam.GetValue("Item3_Data");
g_DBPwd = DlgParam.GetValue("Item4_Data");
DataCmpGoto( nOpType , OT_CANCEL ,"Cancel" );
DataCmpGoto( nOpType , OT_BREAK ,"SdSetDestPath" );
// 调用 VBScript 判断当前连接是否成功,成功的话就返回连接字符串
g_dbConnStr = CallVBSFunction("GetSQLConnStr",g_DBServer,g_DBName,g_DBUser,g_DBPwd );
if(g_dbConnStr == "" )
{
MessageBox(Error_DataBaseConnStr) ;
Goto SetDataBase;
}
Cancel:
}
function void UpdateInstall()
{
Install.DoDialog( "SdSetUpdateMode" );
}
function void OnProcess()
{
Install.SetVarTabValue( "VirtualDir" ,g_virtualDir );
var string strRegIISCmd,strTargetDir ;
Install.DoDialog( "SdProcess" );
DataCmpGoto( nOpType , OT_CANCEL ,"Cancel" );
DataCmpGoto( nOpType , OT_REBOOTDO ,"RebootInstall" );
strTargetDir = Install.GetPath( "PATH_S_TARGETDIR" );
// 调用 VBScript 创建Web虚拟目录
if( Install.GetSetupMode() == SM_FINSTALL)
{
//修改WEB.CONFIG
CallVBSFunction("WriteConfigXml",strTargetDir + "//Web.Config" ,"Connstring",g_dbConnStr) ;
//重新注册IIS
DlgParam.SetValue("Prompt" ,Text_RegIIS);
Install.ShowWaitingDlg( DlgParam );
strRegIISCmd = GetFrameWorkDir() + "aspnet_regiis.exe -i" ;
//Install.ExecConsoleCmd( strRegIISCmd , 1 );
CallVBSFunction("SetIISInfo",g_frameWorkVer) ;
Install.CloseWaitingDlg();
DlgParam.SetValue("Prompt" ,Text_CreateVirtualDir);
Install.ShowWaitingDlg( DlgParam );
CallVBSFunction( "CreateVirtualDir" , g_virtualDir , strTargetDir , "default.aspx" );
Install.CloseWaitingDlg();
}
return;
RebootInstall:
Cancel:
}
function void OnEnd()
{
var string strSetURL;
if( Install.GetSetupState() == SS_INSTALL )
{
Install.DoDialog( "SdFinish" );
if( Install.GetSetupMode() == SM_FINSTALL )
{
strSetURL = "http://127.0.0.1/" + g_virtualDir + "/" + RunPage ;
ShellExec( strSetURL );
}
}
else if( Install.GetSetupState() == SS_INSTALL_REBOOTDO )
Install.DoDialog( "SdRebootDo" );
}
//===================================
// 在反安装时执行的脚本
//===================================
function void OnUninstallBegin()
{
g_virtualDir = RegKey.GetRegStrValue( "HKEY_LOCAL_MACHINE" , "SOFTWARE//HuatuSoft//DocGuarder" , "VirtualDir" , "" );
CallVBSFunction("DeleteVirtualDir", g_virtualDir) ;
Uninstall.Uninstall();
}
function string GetFrameWorkDir()
{
var string strWinPath;
var string strPath;
var string strFrameWorkVer;
// 得到framework 版本号
strFrameWorkVer = Install.GetAppVer("Framework");
//得到WINDOWS目录
strWinPath = Install.GetPath("PATH_S_WIN");
//得到FRAMEWORK目录
strPath = strWinPath + "//Microsoft.NET//Framework//V" + strFrameWorkVer + "//";
return strPath;
}