Ejemplo n.º 1
0
 internal ServiceController(string machineName, System.ServiceProcess.NativeMethods.ENUM_SERVICE_STATUS status)
 {
     this.machineName = ".";
     this.name        = "";
     this.displayName = "";
     this.eitherName  = "";
     if (!SyntaxCheck.CheckMachineName(machineName))
     {
         throw new ArgumentException(Res.GetString("BadMachineName", new object[] { machineName }));
     }
     this.machineName      = machineName;
     this.name             = status.serviceName;
     this.displayName      = status.displayName;
     this.commandsAccepted = status.controlsAccepted;
     this.status           = (ServiceControllerStatus)status.currentState;
     this.type             = status.serviceType;
     this.statusGenerated  = true;
 }
Ejemplo n.º 2
0
        private static ServiceController[] GetServicesOfType(string machineName, int serviceType)
        {
            ServiceController[] controllerArray;
            if (!SyntaxCheck.CheckMachineName(machineName))
            {
                throw new ArgumentException(Res.GetString("BadMachineName", new object[] { machineName }));
            }
            new ServiceControllerPermission(ServiceControllerPermissionAccess.Browse, machineName, "*").Demand();
            CheckEnvironment();
            IntPtr zero         = IntPtr.Zero;
            IntPtr status       = IntPtr.Zero;
            int    resumeHandle = 0;

            try
            {
                int num;
                int num2;
                zero = GetDataBaseHandleWithEnumerateAccess(machineName);
                System.ServiceProcess.UnsafeNativeMethods.EnumServicesStatus(zero, serviceType, 3, IntPtr.Zero, 0, out num, out num2, ref resumeHandle);
                status = Marshal.AllocHGlobal((IntPtr)num);
                System.ServiceProcess.UnsafeNativeMethods.EnumServicesStatus(zero, serviceType, 3, status, num, out num, out num2, ref resumeHandle);
                int num4 = num2;
                controllerArray = new ServiceController[num4];
                for (int i = 0; i < num4; i++)
                {
                    IntPtr ptr = (IntPtr)(((long)status) + (i * Marshal.SizeOf(typeof(System.ServiceProcess.NativeMethods.ENUM_SERVICE_STATUS))));
                    System.ServiceProcess.NativeMethods.ENUM_SERVICE_STATUS structure = new System.ServiceProcess.NativeMethods.ENUM_SERVICE_STATUS();
                    Marshal.PtrToStructure(ptr, structure);
                    controllerArray[i] = new ServiceController(machineName, structure);
                }
            }
            finally
            {
                Marshal.FreeHGlobal(status);
                if (zero != IntPtr.Zero)
                {
                    SafeNativeMethods.CloseServiceHandle(zero);
                }
            }
            return(controllerArray);
        }
 private static ServiceController[] GetServicesOfType(string machineName, int serviceType)
 {
     ServiceController[] controllerArray;
     if (!SyntaxCheck.CheckMachineName(machineName))
     {
         throw new ArgumentException(Res.GetString("BadMachineName", new object[] { machineName }));
     }
     new ServiceControllerPermission(ServiceControllerPermissionAccess.Browse, machineName, "*").Demand();
     CheckEnvironment();
     IntPtr zero = IntPtr.Zero;
     IntPtr status = IntPtr.Zero;
     int resumeHandle = 0;
     try
     {
         int num;
         int num2;
         zero = GetDataBaseHandleWithEnumerateAccess(machineName);
         System.ServiceProcess.UnsafeNativeMethods.EnumServicesStatus(zero, serviceType, 3, IntPtr.Zero, 0, out num, out num2, ref resumeHandle);
         status = Marshal.AllocHGlobal((IntPtr) num);
         System.ServiceProcess.UnsafeNativeMethods.EnumServicesStatus(zero, serviceType, 3, status, num, out num, out num2, ref resumeHandle);
         int num4 = num2;
         controllerArray = new ServiceController[num4];
         for (int i = 0; i < num4; i++)
         {
             IntPtr ptr = (IntPtr) (((long) status) + (i * Marshal.SizeOf(typeof(System.ServiceProcess.NativeMethods.ENUM_SERVICE_STATUS))));
             System.ServiceProcess.NativeMethods.ENUM_SERVICE_STATUS structure = new System.ServiceProcess.NativeMethods.ENUM_SERVICE_STATUS();
             Marshal.PtrToStructure(ptr, structure);
             controllerArray[i] = new ServiceController(machineName, structure);
         }
     }
     finally
     {
         Marshal.FreeHGlobal(status);
         if (zero != IntPtr.Zero)
         {
             SafeNativeMethods.CloseServiceHandle(zero);
         }
     }
     return controllerArray;
 }