[转]用Installshield制作软件包常用的InstallScript--5
prototype NUMBER checkSQLAuth();
function NUMBER checkSQLAuth()
NUMBER nResult,nType,nSize;
STRING szKey,szValue,szKeyName,szSQLServiceName1,szSQLServiceName;
begin
szKeyName = "LoginMode";
nType = REGDB_STRING;
szValue = "";
nSize = -1;
szKey = "SOFTWARE\\Microsoft\\Microsoft SQL Server\\MSSQL.1\\MSSQLServer";
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
if RegDBGetKeyValueEx(szKey,szKeyName,nType,szValue,nSize) < 0 then
return -1;
else
if szValue = "1" then //Windows身份认证
szValue = "2";
if RegDBSetKeyValueEx(szKey,szKeyName,nType,szValue,nSize) < 0 then
MessageBox("修改认证方式失败",WARNING);
return -1;
else//重启SQLServer
//获取服务器名称
szKeyName = "InstalledInstances";
szKey = "Software\\Microsoft\\Microsoft SQL Server";
nResult=RegDBGetKeyValueEx(szKey,szKeyName,nType,szSQLServiceName1, nSize);
if(nResult < 0) then
//MessageBox ("获取数据库服务器名称失败!",INFORMATION);
szSQLServiceName="MSSQL" ;
else
if(szSQLServiceName1="") then
szSQLServiceName="MSSQL";
else if(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 ServiceStopService(szSQLServiceName)< ISERR_SUCCESS then
MessageBox("数据库服务停止失败",WARNING);
endif;
//启动数据库服务
if (ServiceStartService(szSQLServiceName,"")< ISERR_SUCCESS ) then
//SdShowMsg("",FALSE);
//SetDialogTitle ( DLG_MSG_INFORMATION, "数据库服务启动出错" );
MessageBox("数据库服务"+szSQLServiceName+"启动错误!请手动开启数据库服务后再执行软件安装程序。如仍无法解决,请联系系统供应商!",INFORMATION);
//abort;
endif;
endif;
endif;
endif;
//MessageBox(szValue,WARNING);
end;
12.检查SQLServer版本
prototype BOOL checkSqlVersion(STRING);
function BOOL checkSqlVersion(ConnectionStr)
OBJECT pADOConnObj, pADORecordSetObj;
STRING szADOConnObjID, szADORecordSetObjID, szSQL,sVersion;
BOOL IsSQL2k5;
NUMBER nVersion;
begin
IsSQL2k5 = FALSE;
try
// Create ADO Connection Object to connect to the SQL server
szADOConnObjID = "ADODB.Connection";
set pADOConnObj = CreateObject(szADOConnObjID);
// Open the ADO Connection
pADOConnObj.Open(ConnectionStr);
// Create ADO Recordset object for the return
szADORecordSetObjID = "ADODB.Recordset";
set pADORecordSetObj = CreateObject(szADORecordSetObjID);
// Set some ADO Recordset properties
pADORecordSetObj.CursorType = 3;
pADORecordSetObj.ActiveConnection = pADOConnObj;
// Create the SQL string to retrieve the database if it exists
szSQL = "SELECT SERVERPROPERTY('productversion') as versionNo";
// Use the recordset to see if the database exists
pADORecordSetObj.Open(szSQL);
if(!pADORecordSetObj.EOF())then
sVersion = pADORecordSetObj("versionNo");
StrSub(sVersion,sVersion,0,1);
StrToNum(nVersion,sVersion);
if nVersion = 9 && nVersion < 10 then
IsSQL2k5 = TRUE;
else
IsSQL2k5 = FALSE;
endif;
endif;
catch
MessageBox(Err.Description,SEVERE);
set pADOConnObj = NOTHING;
set pADORecordSetObj = NOTHING;
IsSQL2k5 = FALSE;
endcatch;
set pADOConnObj = NOTHING;
set pADORecordSetObj = NOTHING;
return IsSQL2k5;
end;