//窗体
object Form1: TForm1
Left = 192
Top = 107
Width = 442
Height = 246
Caption = ‘Form1’
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
http://www.gaodaima.com/65635.html判断MS SQL Server是否启动_Delphi
Font.Height = -11
Font.Name = ‘MS Sans Serif’
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 216
Top = 40
Width = 32
Height = 13
Caption = ‘Label1’
end
object Button1: TButton
Left = 32
Top = 16
Width = 75
Height = 25
Caption = ‘Button1’
TabOrder = 0
OnClick = Button1Click
end
object Button2: TButton
Left = 48
Top = 104
Width = 75
Height = 25
Caption = ‘Button2’
TabOrder = 1
OnClick = Button2Click
end
object cs: TClientsocket
Active = False
Address = ‘202.99.0.172’
ClientType = ctNonBlocking
Port = 1433
Left = 32
Top = 48
end
object Timer1: TTimer
Interval = 5000
OnTimer = Timer1Timer
Left = 80
Top = 48
end
end
////////////代码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ScktComp, ExtCtrls;
const
SERVICE_STOPPED=1; // Stopped
SERVICE_START_PENDING=2; // Starting
SERVICE_STOP_PENDING=3; // Stopping
SERVICE_RUNNING=4; // Running
SERVICE_CONTINUE_PENDING=5; // Restarting after being paused
SERVICE_PAUSE_PENDING=6; // Pausing
SERVICE_PAUSED=7; //Paused
type
TForm1 = class(TForm)
cs: TClientSocket;
Button1: TButton;
Timer1: TTimer;
Label1: TLabel;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function SQLSCMGetLocalServiceStateA(lpszSvc: PChar;dwErr:PDWORD): Integer;cdecl;external ‘w95scm.dll’;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
cs.Open;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
try
cs.Active := true;
finally
if cs.Active then
Label1.Caption := ‘Runnig’
else
Label1.Caption := ‘Not Runnig’;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
r,e: DWORD;
begin
r := SQLSCMGetLocalServiceStateA(‘MSsqlserver‘,@e);
case r of
SERVICE_STOPPED:
ShowMessage(‘Stoped’);
SERVICE_START_PENDING:
ShowMessage(‘Starting’);
SERVICE_STOP_PENDING:
ShowMessage(‘Stopping’);
SERVICE_RUNNING:
ShowMessage(‘Running’);
SERVICE_CONTINUE_PENDING:
ShowMessage(‘Restarting’);
SERVICE_PAUSE_PENDING:
ShowMessage(‘Pausing’);
SERVICE_PAUSED:
ShowMessage(‘Paused’);
end;
end;
end.
欢迎大家阅读《判断MS SQL Server是否启动_Delphi》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码