这样写,不用uses什么东西.
const
RSP_SIMPLE_SERVICE = $00000001;
RSP_UNREGISTER_SERVICE = $00000000;
type
TRegisterServiceProcess = function (dwProcessID, dwType : DWORD) : DWORD; stdcall;
function RegisterAsService : boolean;
var
RSP : TRegisterServiceProcess;
hMod : THandle;
begin
Result := false;
hMod := LoadLibrary('KERNEL32.DLL');
if hMod=0 then exit;
@RSP := GetProcAddress(hMod, 'RegisterServiceProcess');
if @RSP=nil then exit;
try
if RSP(0, RSP_SIMPLE_SERVICE)=1 then
Result := true;
finally
FreeLibrary(hMod);
end;
end;
function UnRegisterAsService : boolean;
var
RSP : TRegisterServiceProcess;
hMod : THandle;
begin
Result := false;
hMod := LoadLibrary('KERNEL32.DLL');
if hMod=0 then exit;
@RSP := GetProcAddress(hMod, 'RegisterServiceProcess');
if @RSP=nil then exit;
try
if RSP(0, RSP_UNREGISTER_SERVICE)=1 then
Result := true;
finally
FreeLibrary(hMod);
end;
end;
NOTE: NT下无效.