Use InstallShield 12 to check whether ms SQL Server or MSDE is installed

Source: Internet
Author: User
Tags mssqlserver

I have been searching for this stuff on the Internet for a long time, either incomplete or not what I wanted. I finally figured it out and posted it. Please help me to see if there are still defects.

// Global variable
String szsqlservicename; // database server name
String szsqlservicename1; // database server name (cache)
String szsqlservicefilepath; // path of the execution file of the Database Server
String szsqlservicedatarootpath; // Database Server database root path
String szsqlservicefilerootpath; // root path of the Database Server File
String szstartserviceargs; // sum of startup parameters
String szsqlservicerundata0; // database server startup parameter 1
String szsqlservicerundata1; // database server startup parameter 2
String szsqlservicerundata2; // database server startup parameter 3
Number szservicestate; // Database Service startup status

// Check when installation starts
Function onbegin ()
String szmsg;
String skey, skeyarg, svalue, sdata;
String szkey;
Number ntype, nsize;
Number nresult;
String szwaittxt;
Begin

If! Maintenance then
Sdshowmsg ("checking the software runtime environment... please wait", true );
Delay (1 );
// Determine whether Microsoft SQL Server or MSDE is installed.
Skey = "software // Microsoft SQL Server ";
Szmsg = "micorsoft SQL Server or MSDE is not installed. Please install micorsoft SQL Server or MSDE first .";

Regdbsetdefaultroot (HKEY_LOCAL_MACHINE );
Nresult = regdbgetkeyvalueex (skey, "installedinstances", ntype, sdata, nsize );
If (nresult <0) then
Sdshowmsg ("msde2000 is being installed. Please wait...", true );
Delay (1 );
If (launchappandwait ("MSDE // setup.exe", "", laaw_option_wait | laaw_option_maximized) <0) then
Sdshowmsg ("", false );
MessageBox ("msde2000installation failed. Please manually install the msde2000 engine in setup.exe under the optical disk msdedirectory./n. If the problem persists, contact the system supplier! ", Severe );
Abort;
Endif;
Endif;
// Obtain the server name
Nresult = regdbgetkeyvalueex (skey, "installedinstances", ntype, szsqlservicename1, nsize );
If (nresult <0) then
// MessageBox ("An error occurred while obtaining the database server name! ", Information );
Szsqlservicename = "MSSQL ";
Else
If (szsqlservicename1 = "") then
Szsqlservicename = "MSSQL ";
Elseif (szsqlservicename1! = "MSSQLServer") then
Szsqlservicename = "MSSQL $" + szsqlservicename1;
Else
Szsqlservicename = szsqlservicename1;
Endif;
Endif;
// Obtain the root path of the database file
If (szsqlservicename1! = "MSSQLServer") then
Skey = "software // Microsoft SQL Server //" + szsqlservicename1 + "// setup ";
Else
Skey = "software // Microsoft //" + szsqlservicename1 + "// MSSQLServer // setup ";
Endif;
Regdbgetkeyvalueex (skey, "sqldataroot", ntype, szsqlservicedatarootpath, nsize); // database root path
Regdbgetkeyvalueex (skey, "sqldataroot", ntype, szsqlservicefilerootpath, nsize); // file root path
// Path of the database Startup File
Szsqlservicefilepath = szsqlservicefilerootpath + "// binn // sqlservr.exe ";
 
// Obtain the database server startup parameters
If (szsqlservicename1! = "MSSQLServer") then
Skeyarg = "software // 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;

// Check whether the database service is enabled
If (servicegetservicestate (szsqlservicename, szservicestate) <iserr_success) then
// Load
Serviceaddservice (szsqlservicename, szsqlservicefilepath, true, szstartserviceargs );
Endif;
// Start the Database Service
If (servicestartservice (szsqlservicename, "") <iserr_success) then
Sdshowmsg ("", false );
Setdialogtitle (dlg_msg_information, "Database Service Startup error ");
MessageBox ("Database Service" + szsqlservicename + "Startup error! Manually enable the database service before executing the software installation program. /N. If the problem persists, contact the system supplier! ", Information );
Abort;
Endif;
Endif;
End;

Related Article

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.