InstallShield advanced application-Get all SQL services on the local machine

Source: Internet
Author: User
// ================================================ ======================================= //
////
// Function getsqlservers //
//// Obtain all the SQL services of the Local Machine
// 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);
// obtain the server name
regdbsetdefaultroot (HKEY_LOCAL_MACHINE );
nresult = regdbgetkeyvalueex ("Software \ Microsoft SQL Server", "installedinstances", ntype, szsqlservicename1, nsize);
If (nresult <0) then
szsqlservicename = "MSSQL";
else
listaddstring (listid, "(local)", after);
endif;
nresult = regdbgetkeyvalueex ("SOFTWARE \ 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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.