public static bool CreateService( ref IntPtr hService, string ServiceName, string DisplayName, string BinPath, uint DesiredAccess, uint ServiceType, uint StartType, uint ErrorControl) { IntPtr hSCManager = Nt.OpenSCManager(0, 0, 0x0002 /*SC_MANAGER_CREATE_SERVICE*/); if (hSCManager == IntPtr.Zero) { return(false); } hService = Nt.CreateServiceW( hSCManager, ServiceName, DisplayName, DesiredAccess, ServiceType, StartType, ErrorControl, BinPath, 0, 0, 0, 0, 0, 0); Nt.CloseServiceHandle(hSCManager); return(hService != IntPtr.Zero); }
public static bool OpenService(out IntPtr hService, string szServiceName, uint DesiredAccess) { IntPtr hSCManager = Nt.OpenSCManager(0, 0, DesiredAccess); hService = Nt.OpenService(hSCManager, szServiceName, DesiredAccess); Nt.CloseServiceHandle(hSCManager); return(hService != IntPtr.Zero); }
public static void CloseServiceHandle(IntPtr hService) => Nt.CloseServiceHandle(hService);