Beispiel #1
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);
        }
Beispiel #2
0
        public static bool ServiceIsInstalled(string ServiceName)
        {
            bool   flag;
            IntPtr intPtr = ServiceInstaller.OpenSCManager(ServiceManagerRights.Connect);

            try
            {
                IntPtr intPtr1 = ServiceInstaller.OpenService(intPtr, ServiceName, ServiceRights.QueryStatus);
                if (intPtr1 != IntPtr.Zero)
                {
                    ServiceInstaller.CloseServiceHandle(intPtr1);
                    flag = true;
                }
                else
                {
                    flag = false;
                }
            }
            finally
            {
                ServiceInstaller.CloseServiceHandle(intPtr);
            }
            return(flag);
        }
Beispiel #3
0
 private static void StopService(IntPtr hService)
 {
     ServiceInstaller.ControlService(hService, ServiceControl.Stop, new ServiceInstaller.SERVICE_STATUS());
     ServiceInstaller.WaitForServiceStatus(hService, ServiceState.Stopping, ServiceState.Stop);
 }
Beispiel #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);
 }
 private static extern int QueryServiceStatus(IntPtr hService, ServiceInstaller.SERVICE_STATUS lpServiceStatus);
 private static extern int ControlService(IntPtr hService, ServiceControl dwControl, ServiceInstaller.SERVICE_STATUS lpServiceStatus);