//全局变量STRING szSQLServiceName ; //数据库服务器名 STRING szSQLServiceName1 ; //数据库服务器名(缓存) STRING szSQLServiceFilePath ; //数据库服务器执行文件路径 STRING szSQLServiceDataRootPath ; //数据库服务器数据库根路径 STRING szSQLServiceFileRootPath ; //数据库服务器文件根路径 STRING szStartServiceArgs ; //启动参数总和 STRING szSQLServiceRunData0 ; //数据库服务器启动参数1 STRING szSQLServiceRunData1 ; //数据库服务器启动参数2 STRING szSQLServiceRunData2 ; //数据库服务器启动参数3 NUMBER szServiceState ; //数据库服务启动状态 //安装开始时检查function OnBegin() STRING szMsg ; STRING sKey , sKeyArg , sValue , sData ; STRING szKey ; NUMBER nType , nSize ; NUMBER nResult ; STRING szWaitTxt ; begin if !MAINTENANCE then SdShowMsg( " 正在检查软件运行环境...请稍候 " , TRUE) ; Delay( 1 ) ; // 判断系统是否安装Microsoft SQL Server或MSDE sKey = " Software/Microsoft/Microsoft SQL Server " ; szMsg = " Micorsoft SQL Server 或 MSDE没有安装,请先安装Micorsoft SQL Server 或 MSDE. " ; RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE) ; nResult = RegDBGetKeyValueEx ( sKey , " InstalledInstances " , nType , sData , nSize ) ; if ( nResult < 0 )then SdShowMsg( " 正在安装MSDE2000,请稍等... " , TRUE) ; Delay( 1 ) ; if(LaunchAppAndWait( " msde/setup.exe " , "" , LAAW_OPTION_WAIT|LAAW_OPTION_MAXIMIZED)< 0 ) then SdShowMsg( "" , FALSE) ; MessageBox( " 安装MSDE2000失败,请手动执行安装光盘MSDE目录下的setup.exe安装MSDE2000引擎. 如仍无法解决,请联系系统供应商! " , SEVERE) ; abort ; endif ; endif ; //获取服务器名称 nResult = RegDBGetKeyValueEx( sKey , " InstalledInstances " , nType , szSQLServiceName1 , nSize ) ; if(nResult < 0 ) then //MessageBox ( " 获取数据库服务器名称失败! " , INFORMATION) ; szSQLServiceName = " MSSQL " ; else if(szSQLServiceName1 = "" ) then szSQLServiceName = " MSSQL " ; elseif(szSQLServiceName1! = " MSSQLSERVER " ) then szSQLServiceName = " MSSQL$ " +szSQLServiceName1 ; else szSQLServiceName = szSQLServiceName1 ; endif ; endif ; //获取数据库文件根路径 if(szSQLServiceName1! = " MSSQLSERVER " ) then sKey = " Software/Microsoft/Microsoft SQL Server/ " +szSQLServiceName1+ " /Setup " ; else sKey = " Software/Microsoft/ " +szSQLServiceName1+ " /MSSQLServer/Setup " ; endif ; RegDBGetKeyValueEx( sKey , " SQLDataRoot " , nType , szSQLServiceDataRootPath , nSize ) ; //数据库根路径 RegDBGetKeyValueEx( sKey , " SQLDataRoot " , nType , szSQLServiceFileRootPath , nSize ) ; //文件根路径 //数据库启动文件路径 szSQLServiceFilePath = szSQLServiceFileRootPath+ " /Binn/sqlservr.exe " ; //获取数据库服务器启动参数 if(szSQLServiceName1! = " MSSQLSERVER " ) then sKeyArg = " Software/Microsoft/Microsoft SQL Server/ " +szSQLServiceName1+ " /MSSQLServer/Parameters " ; else sKeyArg = " Software/Microsoft/ " +szSQLServiceName1+ " /MSSQLServer/Parameters " ; endif ; RegDBGetKeyValueEx( sKey , " SQLArg0 " , nType , szSQLServiceRunData0 , nSize ) ; RegDBGetKeyValueEx( sKey , " SQLArg1 " , nType , szSQLServiceRunData1 , nSize ) ; RegDBGetKeyValueEx( sKey , " SQLArg2 " , nType , szSQLServiceRunData2 , nSize ) ; szStartServiceArgs = " -c " + szSQLServiceRunData0 + " " +szSQLServiceRunData1+ " " +szSQLServiceRunData2 ; //检测数据库服务是否启动 if(ServiceGetServiceState(szSQLServiceName , szServiceState)< ISERR_SUCCESS) then //加载 ServiceAddService (szSQLServiceName , szSQLServiceName , szSQLServiceName , szSQLServiceFilePath , TRUE , szStartServiceArgs) ; endif ; //启动数据库服务 if (ServiceStartService(szSQLServiceName , "" )< ISERR_SUCCESS ) then SdShowMsg( "" , FALSE) ; SetDialogTitle ( DLG_MSG_INFORMATION , " 数据库服务启动出错 " ) ; MessageBox( " 数据库服务 " +szSQLServiceName+ " 启动错误!请手动开启数据库服务后再执行软件安装程序。如仍无法解决,请联系系统供应商! " , INFORMATION) ; abort ; endif ; endif ; end ;