function OnFirstUIAfter()
STRING szTitle, szMsg1, szMsg2, szOpt1, szOpt2;
NUMBER bvOpt1, bvOpt2;
NUMBER bShowUpdateServiceDlg;
STRING szWaitText;
STRING szServiceName;
NUMBER svServiceState;
STRING szMsde2000, szCmdLine,szStartServiceArgs;
begin
// 如果安装程序以“维护”模式启动
if (MAINTENANCE) then
goto EndProcess;
endif; // 检查系统是否安装了 MSDE 2000 SP4
szWaitText = "正在检查系统是否安装了 MSDE2000 SP4 …….";
SdShowMsg( szWaitText, TRUE);
szServiceName = "MSSQL$TOPSOFT";
if(ServiceGetServiceState(szServiceName, svServiceState) < ISERR_SUCCESS) then
// 没有安装 MSDE,转安装处理
goto InstallMSDE;
endif;
goto StartMSDE;
InstallMSDE: // 安装数据库服务
szWaitText = "正在安装 MSDE2000 SP4。这个过程需要几分钟,请稍等";
SdShowMsg(szWaitText, TRUE);
szMsde2000 = SRCDIR ^ "MSDE" ^ "setup.exe";
// 将 MSDE 2000 SP4 安装到系统 Program File 目录下
szCmdLine = "TARGETDIR=\"" + PROGRAMFILES + "\" /q";
if(LaunchAppAndWait(szMsde2000, szCmdLine, LAAW_OPTION_WAIT|LAAW_OPTION_MAXIMIZED) < 0 ) then
MessageBox ("安装 MSDE2000 SP4 失败,请联系系统管理员!", SEVERE);
goto EndProcess;
endif;StartMSDE: // 启动 MSDE2000 服务
szWaitText = "正在启动 MSDE2000 SP4 …….";
SdShowMsg( szWaitText, TRUE);
// 安装了 MSDE 2000, 试着启动服务
szStartServiceArgs = "";
if(svServiceState != SERVICE_RUNNING) then
if (ServiceStartService (szServiceName, szStartServiceArgs) < ISERR_SUCCESS ) then
MessageBox ("启动服务" + szServiceName + "出错。", SEVERE);
goto EndProcess;
endif;
endif; // 加载用户数据库
szWaitText = "正在创建所需数据库.";
SdShowMsg(szWaitText, TRUE);
Delay(2);
// 先试着分离先前已经加载的数据库
szCmdLine = "-E -Q \"exec exec sp_detach_db TestDB \"";
if(LaunchAppAndWait("osql.exe ", szCmdLine, LAAW_OPTION_WAIT|LAAW_OPTION_HIDDEN) < 0) then
MessageBox ("分离原来的数据库失败!请确认系统中已安装 MSDE 2000 SP4 并且服务已启动。\n如问题仍无法解决,请与联系统管理员联系!", SEVERE);
endif;
// 将数据文件复制到程序安装目录
CreateDir( TARGETDIR ^ "Data");
CopyFile( SRCDIR ^ "Data" ^ "Tsmis15_Data.MDF", TARGETDIR ^ "Data" ^ "Tsmis15_Data.MDF");
CopyFile( SRCDIR ^ "Data" ^ "Tsmis15_Log.LDF", TARGETDIR ^ "Data" ^ "Tsmis15_Log.LDF");
// 附加数据库
szCmdLine = "-E -Q \"exec sp_attach_db 'tsmis20', '"+ TARGETDIR ^ "Data" ^ "Tsmis15_Data.MDF', '" + TARGETDIR ^ "Data" ^ "Tsmis15_Log.LDF' \""; if (LaunchAppAndWait("osql.exe ", szCmdLine, LAAW_OPTION_WAIT|LAAW_OPTION_HIDDEN) < 0) then
MessageBox ("数据库创建失败!请确认系统中已安装 MSDE 2000 SP4 并且服务已启动。\n如问题仍无法解决,请与联系统管理员联系!", SEVERE);
endif;
SdShowMsg(szWaitText, FALSE);
EndProcess:
// 以下代码是系统自动插入的
ShowObjWizardPages(NEXT);
szTitle = "";
szMsg1 = "";
szMsg2 = "";
szOpt1 = "";
szOpt2 = "";
bvOpt1 = FALSE;
bvOpt2 = FALSE; // Set this to true if you have the update service enabled, and if you want to check for updates.
// Note: the ISUS Starter Edition does not support checking for updates programatically. So,
// only set this to true if you have at least the ISUS Professional Edition.
bShowUpdateServiceDlg = FALSE;
//{{IS_SCRIPT_TAG(Dlg_SdDinishEx)
if ( BATCH_INSTALL ) then
SdFinishReboot ( szTitle , szMsg1 , SYS_BOOTMACHINE , szMsg2 , 0 );
else
// If the update service is enabled, show finish dialog that includes
// update check option.
if( bShowUpdateServiceDlg && ( ENABLED_ISERVICES & SERVICE_ISUPDATE ) ) then if( SdFinishUpdateEx( szTitle, szMsg1, szMsg2, szOpt1, szOpt2, TRUE ) ) then // Don't check for updates in silent mode.
if( MODE != SILENTMODE ) then
UpdateServiceCheckForUpdates( "", FALSE );
endif; endif; else
SdFinish ( szTitle , szMsg1 , szMsg2 , szOpt1 , szOpt2 , bvOpt1 , bvOpt2 );
endif; endif;
//}}IS_SCRIPT_TAG(Dlg_SdDinishEx)
end; 上述代码是我在网上找到的,前面都好用,就是后面附件数据库附加不上 szCmdLine = "-E -Q \"exec sp_attach_db 'tsmis20', '"+ TARGETDIR ^ "Data" ^ "Tsmis15_Data.MDF', '" + TARGETDIR ^ "Data" ^ "Tsmis15_Log.LDF' \"";
STRING szTitle, szMsg1, szMsg2, szOpt1, szOpt2;
NUMBER bvOpt1, bvOpt2;
NUMBER bShowUpdateServiceDlg;
STRING szWaitText;
STRING szServiceName;
NUMBER svServiceState;
STRING szMsde2000, szCmdLine,szStartServiceArgs;
begin
// 如果安装程序以“维护”模式启动
if (MAINTENANCE) then
goto EndProcess;
endif; // 检查系统是否安装了 MSDE 2000 SP4
szWaitText = "正在检查系统是否安装了 MSDE2000 SP4 …….";
SdShowMsg( szWaitText, TRUE);
szServiceName = "MSSQL$TOPSOFT";
if(ServiceGetServiceState(szServiceName, svServiceState) < ISERR_SUCCESS) then
// 没有安装 MSDE,转安装处理
goto InstallMSDE;
endif;
goto StartMSDE;
InstallMSDE: // 安装数据库服务
szWaitText = "正在安装 MSDE2000 SP4。这个过程需要几分钟,请稍等";
SdShowMsg(szWaitText, TRUE);
szMsde2000 = SRCDIR ^ "MSDE" ^ "setup.exe";
// 将 MSDE 2000 SP4 安装到系统 Program File 目录下
szCmdLine = "TARGETDIR=\"" + PROGRAMFILES + "\" /q";
if(LaunchAppAndWait(szMsde2000, szCmdLine, LAAW_OPTION_WAIT|LAAW_OPTION_MAXIMIZED) < 0 ) then
MessageBox ("安装 MSDE2000 SP4 失败,请联系系统管理员!", SEVERE);
goto EndProcess;
endif;StartMSDE: // 启动 MSDE2000 服务
szWaitText = "正在启动 MSDE2000 SP4 …….";
SdShowMsg( szWaitText, TRUE);
// 安装了 MSDE 2000, 试着启动服务
szStartServiceArgs = "";
if(svServiceState != SERVICE_RUNNING) then
if (ServiceStartService (szServiceName, szStartServiceArgs) < ISERR_SUCCESS ) then
MessageBox ("启动服务" + szServiceName + "出错。", SEVERE);
goto EndProcess;
endif;
endif; // 加载用户数据库
szWaitText = "正在创建所需数据库.";
SdShowMsg(szWaitText, TRUE);
Delay(2);
// 先试着分离先前已经加载的数据库
szCmdLine = "-E -Q \"exec exec sp_detach_db TestDB \"";
if(LaunchAppAndWait("osql.exe ", szCmdLine, LAAW_OPTION_WAIT|LAAW_OPTION_HIDDEN) < 0) then
MessageBox ("分离原来的数据库失败!请确认系统中已安装 MSDE 2000 SP4 并且服务已启动。\n如问题仍无法解决,请与联系统管理员联系!", SEVERE);
endif;
// 将数据文件复制到程序安装目录
CreateDir( TARGETDIR ^ "Data");
CopyFile( SRCDIR ^ "Data" ^ "Tsmis15_Data.MDF", TARGETDIR ^ "Data" ^ "Tsmis15_Data.MDF");
CopyFile( SRCDIR ^ "Data" ^ "Tsmis15_Log.LDF", TARGETDIR ^ "Data" ^ "Tsmis15_Log.LDF");
// 附加数据库
szCmdLine = "-E -Q \"exec sp_attach_db 'tsmis20', '"+ TARGETDIR ^ "Data" ^ "Tsmis15_Data.MDF', '" + TARGETDIR ^ "Data" ^ "Tsmis15_Log.LDF' \""; if (LaunchAppAndWait("osql.exe ", szCmdLine, LAAW_OPTION_WAIT|LAAW_OPTION_HIDDEN) < 0) then
MessageBox ("数据库创建失败!请确认系统中已安装 MSDE 2000 SP4 并且服务已启动。\n如问题仍无法解决,请与联系统管理员联系!", SEVERE);
endif;
SdShowMsg(szWaitText, FALSE);
EndProcess:
// 以下代码是系统自动插入的
ShowObjWizardPages(NEXT);
szTitle = "";
szMsg1 = "";
szMsg2 = "";
szOpt1 = "";
szOpt2 = "";
bvOpt1 = FALSE;
bvOpt2 = FALSE; // Set this to true if you have the update service enabled, and if you want to check for updates.
// Note: the ISUS Starter Edition does not support checking for updates programatically. So,
// only set this to true if you have at least the ISUS Professional Edition.
bShowUpdateServiceDlg = FALSE;
//{{IS_SCRIPT_TAG(Dlg_SdDinishEx)
if ( BATCH_INSTALL ) then
SdFinishReboot ( szTitle , szMsg1 , SYS_BOOTMACHINE , szMsg2 , 0 );
else
// If the update service is enabled, show finish dialog that includes
// update check option.
if( bShowUpdateServiceDlg && ( ENABLED_ISERVICES & SERVICE_ISUPDATE ) ) then if( SdFinishUpdateEx( szTitle, szMsg1, szMsg2, szOpt1, szOpt2, TRUE ) ) then // Don't check for updates in silent mode.
if( MODE != SILENTMODE ) then
UpdateServiceCheckForUpdates( "", FALSE );
endif; endif; else
SdFinish ( szTitle , szMsg1 , szMsg2 , szOpt1 , szOpt2 , bvOpt1 , bvOpt2 );
endif; endif;
//}}IS_SCRIPT_TAG(Dlg_SdDinishEx)
end; 上述代码是我在网上找到的,前面都好用,就是后面附件数据库附加不上 szCmdLine = "-E -Q \"exec sp_attach_db 'tsmis20', '"+ TARGETDIR ^ "Data" ^ "Tsmis15_Data.MDF', '" + TARGETDIR ^ "Data" ^ "Tsmis15_Log.LDF' \"";
主要程序:
//检查是否安装MSDE service;
if(ServiceGetServiceState(szServiceName, svServiceState) < ISERR_SUCCESS) then
goto InstallMSDE;
endif;
goto StartMSDE; //安装MSDE;
InstallMSDE:
TARGETDIR ^ "Server" ^"MSDE" ^ "setup.exe";
szCmdLine = "TARGETDIR=\"" + PROGRAMFILES + "\" reboot=ReallySuppress /qn /i";
if(LaunchAppAndWait(szMsde2000 , szCmdLine, LAAW_OPTION_WAIT|LAAW_OPTION_MAXIMIZED) < 0 ) then
MessageBox ("install failed",SEVERE);
endif; szSQLsvr = "(local)" ^ "Example";
//启动MSDE;
StartMSDE:
szStartServiceArgs = "";
if(ServiceGetServiceState(szServiceName,svServiceState) < ISERR_SUCCESS) then
MessageBox ("获取服务" + szServiceName + "出错", SEVERE);
if (ServiceStartService (szServiceName, szStartServiceArgs) < ISERR_SUCCESS ) then
MessageBox ("启动服务" + szServiceName + "?出错", SEVERE);
//abort;
endif;
else
if(svServiceState != SERVICE_RUNNING) then
if (ServiceStartService (szServiceName, szStartServiceArgs) < ISERR_SUCCESS ) then
MessageBox ("启动服务" + szServiceName + "出错", SEVERE);
//abort;
endif;
endif;
endif; //分离加载数据库及用户;
szSQLsvr = "(local)" ^ "Example";
szCmdLine = "-U \"sa\" -P \"pwd\" -S "+szSQLsvr+" -Q \"exec sp_detach_db 'TestDB' \"";
if(LaunchAppAndWait("osql.exe ", szCmdLine, LAAW_OPTION_WAIT|LAAW_OPTION_HIDDEN) < 0) then
MessageBox ("Detach failed", SEVERE);
endif; szCmdLine = "-U \"sa\" -P \"pwd\" -S "+szSQLsvr+" -Q \"exec sp_attach_db 'TestDB','"+TARGETDIR^ "Server" ^ "Data" ^ "TestDB_data.mdf', '"+TARGETDIR^ "Server"^"Data"^"TestDB_log.ldf'\"";
if (LaunchAppAndWait("osql.exe ", szCmdLine, LAAW_OPTION_WAIT|LAAW_OPTION_HIDDEN) < 0) then
MessageBox ("Attach failed", SEVERE);
endif; szCmdLine = "-U \"sa\" -P \"pwd\" -S "+szSQLsvr+" -i \""+TARGETDIR ^ "Server" ^ "MSDE" ^ "TestDBAddUser.sql \"";
if (LaunchAppAndWait("osql.exe ", szCmdLine, LAAW_OPTION_WAIT|LAAW_OPTION_HIDDEN) < 0) then
MessageBox ("Add User failed", SEVERE);
endif;