InstallShield高级应用--获取本机所有的SQL服务

//=====================================================================//
// //
// function GetSQLServers //
// //获取本机所有的SQL服务
// purpose get the local SQL servers //
// //
// argment //
// //
// return local SQL server list //
// //
// author chenhuicong 2010-12-24 //
// //
//=====================================================================//


EXPORT prototype LIST GetSQLServers();

function LIST GetSQLServers()
OBJECT objSqlServers,objItem,objAQLDMOApp;
string szSQLDMOSQLServer,szSQLDMOApp,szItem,szSQLServiceName1,szSQLServiceName;
LIST listID;
NUMBER nItemCnt,nStep,nType,nSize,nResult;
begin
/*nStep =0;
szSQLDMOApp ="SQLDMO.Application";
set objAQLDMOApp = CreateObject(szSQLDMOApp);
try
set objItem = objAQLDMOApp.ListAvailableSQLServers();
nItemCnt = objItem.Count;
nStep =1;
while(nStep < 5)
szItem = objItem.Item(nStep);
if(szItem[0] = "(" ) then
ListAddString (listID, szItem, AFTER);
endif;
nStep++;
endwhile;
catch
listID = NOTHING;
objItem = NOTHING;
endcatch;

if(szSQLServiceName1="") then
szSQLServiceName="MSSQL";
ListAddString (listID, szSQLServiceName, AFTER);
elseif(szSQLServiceName1!="MSSQLSERVER") then
szSQLServiceName="MSSQL$"+szSQLServiceName1;
ListAddString (listID, szSQLServiceName, AFTER);
else
szSQLServiceName=szSQLServiceName1;
ListAddString (listID, szSQLServiceName, AFTER);
endif;
*/

listID = ListCreate (STRINGLIST);
//获取服务器名称
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
nResult=RegDBGetKeyValueEx( "SOFTWARE\\Microsoft\\Microsoft SQL Server", "InstalledInstances", nType, szSQLServiceName1, nSize );
if(nResult < 0) then
szSQLServiceName="MSSQL" ;
else
ListAddString (listID, "(local)", AFTER);
endif;
nResult=RegDBGetKeyValueEx( "SOFTWARE\\Microsoft\\Microsoft SQL Server\\SQLEXPRESS\\Setup", "SQLPath", nType, szSQLServiceName1, nSize );
if(nResult < 0) then
szSQLServiceName="MSSQL" ;
else
ListAddString (listID, "(local)\\Express", AFTER);
endif;
return listID;
end;

posted @ 2012-05-11 11:04  ☆会飞的鱼☆  阅读(522)  评论(0编辑  收藏  举报