Delphi Win32 launches SQL ServerUnit Unit2 using the Service API and SQL Server Self-provided Tools SCM.
interface procedure RunMSSQLSERVICE; implementationuses Windows, WinSvc; procedure RunMSSQLSERVICE; var SrvHandle: SC_HANDLE; Service_Status: _SERVICE_STATUS; SrvStatus: Integer; begin TRY SrvHandle: = OpenSCManager ( '', SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS); SrvHandle: = OpenService (SrvHandle, PChar ( ' MSSQLSERVER '), service_query_status or service_start); if QueryServiceStatus (srvhandle, Service_Status) THEN BEGIN
SRVSTATUS: = service_status.dwcurrentState; if srvstatus = service_stopped The begin Winexec ('scm -action 1 -slient 1 -service mssqlserver', sw_normal); end; end; end;
End. -------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------ VC # 2005 Express in .net Under the framework, you only need to encapsulate ServiceApi's ServiceController component to help #Region use Directives
Using system.collections.gener; using system.data; using system.drawing; using system.windows.form;
#ndregion
Namespace WindowsApplication1 {Partial Class Form1: form {public form1 () {itializationcomponent ();
private void button1_Click (object sender, EventArgs e) {try {this.serviceController1.ServiceName = "MSSQLServer"; if (this.serviceController1.Status = System.ServiceProcess.ServiceControllerStatus.Stopped!) {this.serviceController1.Start ();} } CatCH {