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