예제 #1
0
        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)));
            }
        }
예제 #2
0
        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));
        }
예제 #3
0
        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));
            }
        }
예제 #4
0
 static extern bool QueryServiceObjectSecurity(SafeServiceHandle hService,
                                               SecurityInformation dwSecurityInformation,
                                               [Out] byte[] lpSecurityDescriptor,
                                               int cbBufSize,
                                               out int pcbBytesNeeded);
예제 #5
0
 static extern SafeServiceHandle OpenService(
     SafeServiceHandle hSCManager,
     string lpServiceName,
     ServiceAccessRights dwDesiredAccess
     );