您的位置:首页 > 数据库

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

2012-05-11 11:04 281 查看
//=====================================================================//
// //
// 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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: