private static ServiceSecurityInformation GetServiceSecurityInformation(SafeServiceHandle scm, string name) { using (SafeServiceHandle service = OpenService(scm, name, ServiceAccessRights.QueryConfig | ServiceAccessRights.ReadControl)) { if (service.IsInvalid) { throw new Win32Exception(); } return(new ServiceSecurityInformation(name, GetServiceSecurityDescriptor(service), GetTriggersForService(service))); } }
static SecurityDescriptor GetServiceSecurityDescriptor(SafeServiceHandle handle) { int required = 0; byte[] sd = new byte[8192]; if (!QueryServiceObjectSecurity(handle, SecurityInformation.AllBasic, sd, sd.Length, out required)) { throw new Win32Exception(); } return(new SecurityDescriptor(sd)); }
public static ServiceSecurityInformation GetServiceSecurityInformation(string name) { using (SafeServiceHandle scm = OpenSCManager(null, null, ServiceControlManagerAccessRights.Connect | ServiceControlManagerAccessRights.ReadControl)) { if (scm.IsInvalid) { throw new Win32Exception(); } return(GetServiceSecurityInformation(scm, name)); } }
static extern bool QueryServiceObjectSecurity(SafeServiceHandle hService, SecurityInformation dwSecurityInformation, [Out] byte[] lpSecurityDescriptor, int cbBufSize, out int pcbBytesNeeded);
static extern SafeServiceHandle OpenService( SafeServiceHandle hSCManager, string lpServiceName, ServiceAccessRights dwDesiredAccess );