Example #1
0
        public Boolean BDSID_StopDriver()
        {
            Interop.SERVICE_STATUS serviceStatus = new Interop.SERVICE_STATUS();

            IntPtr hSCManager = Interop.OpenSCManager(null, null, (uint)Interop.SCM_ACCESS.SC_MANAGER_ALL_ACCESS);

            if (hSCManager != IntPtr.Zero)
            {
                IntPtr hService = Interop.OpenService(hSCManager, "BZHDELLSMMIO", Interop.SERVICE_ALL_ACCESS);

                Interop.CloseServiceHandle(hSCManager);

                if (hService != IntPtr.Zero)
                {
                    Boolean bResult = Interop.ControlService(hService, Interop.SERVICE_CONTROL.STOP, ref serviceStatus);
                    Interop.CloseServiceHandle(hService);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Example #2
0
        /// Stops the service. If any other services depend on this one for operation,
        /// they will be stopped first. The DependentServices property lists this set
        /// of services.
        public unsafe void Stop()
        {
            IntPtr serviceHandle = GetServiceHandle(Interop.SERVICE_STOP);

            try
            {
                // Before stopping this service, stop all the dependent services that are running.
                // (It's OK not to cache the result of getting the DependentServices property because it caches on its own.)
                for (int i = 0; i < DependentServices.Length; i++)
                {
                    ServiceController currentDependent = DependentServices[i];
                    currentDependent.Refresh();
                    if (currentDependent.Status != ServiceControllerStatus.Stopped)
                    {
                        currentDependent.Stop();
                        currentDependent.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 30));
                    }
                }

                Interop.SERVICE_STATUS status = new Interop.SERVICE_STATUS();
                bool result = Interop.mincore.ControlService(serviceHandle, Interop.CONTROL_STOP, &status);
                if (!result)
                {
                    Exception inner = new Win32Exception(Marshal.GetLastWin32Error());
                    throw new InvalidOperationException(SR.Format(SR.StopService, ServiceName, _machineName), inner);
                }
            }
            finally
            {
                Interop.mincore.CloseServiceHandle(serviceHandle);
            }
        }
Example #3
0
        private unsafe void GenerateStatus()
        {
            if (!_statusGenerated)
            {
                IntPtr serviceHandle = GetServiceHandle(Interop.SERVICE_QUERY_STATUS);
                try
                {
                    Interop.SERVICE_STATUS svcStatus = new Interop.SERVICE_STATUS();
                    bool success = Interop.mincore.QueryServiceStatus(serviceHandle, &svcStatus);
                    if (!success)
                    {
                        throw new Win32Exception(Marshal.GetLastWin32Error());
                    }

                    _commandsAccepted = svcStatus.controlsAccepted;
                    _status           = (ServiceControllerStatus)svcStatus.currentState;
                    _type             = svcStatus.serviceType;
                    _statusGenerated  = true;
                }
                finally
                {
                    Interop.mincore.CloseServiceHandle(serviceHandle);
                }
            }
        }
Example #4
0
        /// Continues a service after it has been paused.
        public unsafe void Continue()
        {
            IntPtr serviceHandle = GetServiceHandle(Interop.SERVICE_PAUSE_CONTINUE);

            try
            {
                Interop.SERVICE_STATUS status = new Interop.SERVICE_STATUS();
                bool result = Interop.mincore.ControlService(serviceHandle, Interop.CONTROL_CONTINUE, &status);
                if (!result)
                {
                    Exception inner = new Win32Exception(Marshal.GetLastWin32Error());
                    throw new InvalidOperationException(SR.Format(SR.ResumeService, ServiceName, _machineName), inner);
                }
            }
            finally
            {
                Interop.mincore.CloseServiceHandle(serviceHandle);
            }
        }