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;
作者:chhuic
出处:http://chhuic.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。