www.pudn.com > UCtrl.rar > SYSCtrl.pas
unit SYSCtrl;
interface
uses Windows, SYServer;
function SYSInstall(Path: PChar): Bool;
function SYStartAndRun(): Bool;
function SYStopAndFree(): Bool;
function SYSUnInstall():Bool;
type
MSysDataCtl = packed record
Ctl: LongInt;
Sty: LongInt;
end;
const
SySDiscrip = 'ÈôÎÒ';
SYServerName = 'TSinJoy';
SYSLinkName = '\\.\TSinJoy'; //-- ServerLinkName
implementation
function SYSInstall(Path: PChar): Bool;
var
Serv: TSYServer;
begin
Serv := TSYServer.Create;
Result := Serv.ServiceInstall(SYServerName, PChar(SySDiscrip), Path) <> INVALID_HANDLE_VALUE;
Serv.Free;
end;
function SYStartAndRun(): Bool;
var
Serv: TSYServer;
Hcd, State: DWORD;
Hon: MSysDataCtl; //-- HookOn
begin
Serv := TSYServer.Create;
Hcd := Serv.CTL_CODE($80, $888, 0, 0);
Hon.Ctl := 1;
Hon.Sty := 1;
State := Serv.ServiceStart(SYServerName);
Result := (State <> 0) and (State <> 3) and //-- 2 1 is true
(Serv.IOCExec(SYSLinkName, Hcd, @Hon, nil, Sizeof(MSysDataCtl), 0));
Serv.Free;
end;
function SYStopAndFree(): Bool;
var
Serv: TSYServer;
Hcd: DWORD;
Hof: MSysDataCtl; //-- HookOff
begin
Serv := TSYServer.Create;
Hcd := Serv.CTL_CODE($80, $888, 0, 0);
Hof.Ctl := 0;
Hof.Sty := 1;
Serv.IOCExec(SYSLinkName, Hcd, @Hof, nil, Sizeof(MSysDataCtl), 0);
Result :=(Serv.ServiceStop(SYServerName) <> 3);
Serv.Free;
end;
function SYSUnInstall():Bool;
var
Serv: TSYServer;
begin
Serv := TSYServer.Create;
Result:=Serv.ServiceUnInstall(SYServerName)=2;
Serv.Free;
end;
end.