Example #1
0
 private static ServiceState GetServiceStatus(IntPtr hService)
 {
     ServiceInstaller.SERVICE_STATUS sERVICESTATU = new ServiceInstaller.SERVICE_STATUS();
     if (ServiceInstaller.QueryServiceStatus(hService, sERVICESTATU) == 0)
     {
         throw new ApplicationException("Failed to query service status.");
     }
     return(sERVICESTATU.dwCurrentState);
 }
Example #2
0
        private static bool WaitForServiceStatus(IntPtr hService, ServiceState WaitStatus, ServiceState DesiredStatus)
        {
            ServiceInstaller.SERVICE_STATUS sERVICESTATU = new ServiceInstaller.SERVICE_STATUS();
            ServiceInstaller.QueryServiceStatus(hService, sERVICESTATU);
            if (sERVICESTATU.dwCurrentState == DesiredStatus)
            {
                return(true);
            }
            int tickCount = Environment.TickCount;
            int num       = sERVICESTATU.dwCheckPoint;

            do
            {
Label0:
                if (sERVICESTATU.dwCurrentState != WaitStatus)
                {
                    break;
                }
                int num1 = sERVICESTATU.dwWaitHint / 10;
                if (num1 < 1000)
                {
                    num1 = 1000;
                }
                else if (num1 > 10000)
                {
                    num1 = 10000;
                }
                Thread.Sleep(num1);
                if (ServiceInstaller.QueryServiceStatus(hService, sERVICESTATU) == 0)
                {
                    break;
                }
                if (sERVICESTATU.dwCheckPoint <= num)
                {
                    continue;
                }
                tickCount = Environment.TickCount;
                num       = sERVICESTATU.dwCheckPoint;
                goto Label0;
            }while (Environment.TickCount - tickCount <= sERVICESTATU.dwWaitHint);
            return(sERVICESTATU.dwCurrentState == DesiredStatus);
        }
Example #3
0
 private static extern int ControlService(IntPtr hService, ServiceControl dwControl, ServiceInstaller.SERVICE_STATUS lpServiceStatus);
Example #4
0
 private static void StartService(IntPtr hService)
 {
     ServiceInstaller.SERVICE_STATUS sERVICESTATU = new ServiceInstaller.SERVICE_STATUS();
     ServiceInstaller.StartService(hService, 0, 0);
     ServiceInstaller.WaitForServiceStatus(hService, ServiceState.Starting, ServiceState.Run);
 }
Example #5
0
 private static extern int QueryServiceStatus(IntPtr hService, ServiceInstaller.SERVICE_STATUS lpServiceStatus);
 private static bool WaitForServiceStatus(IntPtr hService, ServiceState WaitStatus, ServiceState DesiredStatus)
 {
     ServiceInstaller.SERVICE_STATUS sERVICESTATU = new ServiceInstaller.SERVICE_STATUS();
     ServiceInstaller.QueryServiceStatus(hService, sERVICESTATU);
     if (sERVICESTATU.dwCurrentState == DesiredStatus)
     {
         return true;
     }
     int tickCount = Environment.TickCount;
     int num = sERVICESTATU.dwCheckPoint;
     do
     {
     Label0:
         if (sERVICESTATU.dwCurrentState != WaitStatus)
         {
             break;
         }
         int num1 = sERVICESTATU.dwWaitHint / 10;
         if (num1 < 1000)
         {
             num1 = 1000;
         }
         else if (num1 > 10000)
         {
             num1 = 10000;
         }
         Thread.Sleep(num1);
         if (ServiceInstaller.QueryServiceStatus(hService, sERVICESTATU) == 0)
         {
             break;
         }
         if (sERVICESTATU.dwCheckPoint <= num)
         {
             continue;
         }
         tickCount = Environment.TickCount;
         num = sERVICESTATU.dwCheckPoint;
         goto Label0;
     }
     while (Environment.TickCount - tickCount <= sERVICESTATU.dwWaitHint);
     return sERVICESTATU.dwCurrentState == DesiredStatus;
 }
 private static void StartService(IntPtr hService)
 {
     ServiceInstaller.SERVICE_STATUS sERVICESTATU = new ServiceInstaller.SERVICE_STATUS();
     ServiceInstaller.StartService(hService, 0, 0);
     ServiceInstaller.WaitForServiceStatus(hService, ServiceState.Starting, ServiceState.Run);
 }
 private static ServiceState GetServiceStatus(IntPtr hService)
 {
     ServiceInstaller.SERVICE_STATUS sERVICESTATU = new ServiceInstaller.SERVICE_STATUS();
     if (ServiceInstaller.QueryServiceStatus(hService, sERVICESTATU) == 0)
     {
         throw new ApplicationException("Failed to query service status.");
     }
     return sERVICESTATU.dwCurrentState;
 }