1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22:
| Uses WinSvc; procedure InstallService(ServiceName, DisplayName: PChar; FileName: String); var SCManager: SC_HANDLE; Service: SC_HANDLE; begin SCManager := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS); if SCManager = 0 then Exit; try Service := CreateService(SCManager, ServiceName, DisplayName, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_IGNORE, pchar(FileName), nil, nil, nil, nil, nil); CloseServiceHandle(Service); finally CloseServiceHandle(SCManager); end; end; procedure TForm1.Button1Click(Sender: TObject); begin InstallService('SD', 'Service Demo', ParamStr(0)); end; |