public bool Delete() { IntPtr manager = AdvApi32.OpenSCManager(null, null, AdvApi32.SC_MANAGER_ACCESS_MASK.SC_MANAGER_ALL_ACCESS); if (manager == IntPtr.Zero) { return(false); } IntPtr service = AdvApi32.OpenService(manager, _id, AdvApi32.SERVICE_ACCESS_MASK.SERVICE_ALL_ACCESS); if (service == IntPtr.Zero) { return(true); } AdvApi32.SERVICE_STATUS status = new AdvApi32.SERVICE_STATUS(); AdvApi32.ControlService(service, AdvApi32.SERVICE_CONTROL.SERVICE_CONTROL_STOP, ref status); AdvApi32.DeleteService(service); AdvApi32.CloseServiceHandle(service); AdvApi32.CloseServiceHandle(manager); return(true); }