📄 服务器启动与关闭 (2001年3月27日).txt
字号:
服务器启动与关闭 (2001年3月27日)
网友更新 分类:文件系统 作者:meimaoyanjing 推荐:mei 阅读次数:492
(http://www.codesky.net)
--------------------------------------------------------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses
WinSvc, WinTypes;
function ServiceGetKeyName(
sMachine,
sServiceDispName : string ) : string;
var
//
// service control
// manager handle
schm : SC_Handle;
//
// max key name len
nMaxNameLen : dWORD;
//
// temp. string
psServiceName : PChar;
begin
Result := '';
// expect a service key
// name shorter than 255
// characters
nMaxNameLen := 255;
// connect to the service
// control manager
schm := OpenSCManager(
PChar(sMachine),
Nil,
SC_MANAGER_CONNECT);
// if successful...
if(schm > 0)then
begin
psServiceName :=
StrAlloc(nMaxNameLen+1);
if(nil <> psServiceName)then
begin
if( GetServiceKeyName(
schm,
PChar(sServiceDispName),
psServiceName,
nMaxNameLen))then
begin
psServiceName
[nMaxNameLen] := #0;
Result :=
StrPas( psServiceName );
end;
StrDispose(psServiceName);
end;
// close service control
// manager handle
CloseServiceHandle(schm);
end;
end;
function ServiceStart(
sMachine,
sService : string ) : boolean;
var
//
// service control
// manager handle
schm,
//
// service handle
schs : SC_Handle;
//
// service status
ss : TServiceStatus;
//
// temp char pointer
psTemp : PChar;
//
// check point
dwChkP : DWord;
begin
//ss.dwCurrentState := -1;
// connect to the service
// control manager
schm := OpenSCManager(PChar(sMachine), Nil, SC_MANAGER_CONNECT);
// if successful...
if(schm > 0)then
begin
// open a handle to
// the specified service
schs := OpenService(schm,PChar(sService),SERVICE_START or SERVICE_QUERY_STATUS);
// we want to
// start the service and
// query service status
// if successful...
if(schs > 0)then
begin
psTemp := Nil;
if(StartService(schs, 0, psTemp)) then
begin
// check status
if(QueryServiceStatus(schs,ss)) then
begin
while(SERVICE_RUNNING<> ss.dwCurrentState)do
begin
//
// dwCheckPoint contains a
// value that the service
// increments periodically
// to report its progress
// during a lengthy
// operation.
//
// save current value
//
dwChkP := ss.dwCheckPoint;
//
// wait a bit before
// checking status again
//
// dwWaitHint is the
// estimated amount of time
// the calling program
// should wait before calling
// QueryServiceStatus() again
//
// idle events should be
// handled here...
//
Sleep(ss.dwWaitHint);
application.ProcessMessages;
if(not QueryServiceStatus(
schs,
ss))then
begin
// couldn't check status
// break from the loop
break;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -