文章来源:N搜网-中国网上商店商品服务搜索门户 WWW.NSALL.COM判断MS SQL Server是否启动 //窗体 object Form1: TForm1 Left = 192 Top = 107 Width = 442 Height = 246 Caption = 'Form1' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText 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
[N搜网-中国网上商店商品服务搜索门户]:[本文章由N搜网于2006-8-17录入系统,网址:www.nsall.com]
|