示例#1
0
        /// <summary>
        /// Returns the status of all currently existing services on this SCM
        /// </summary>
        /// <param name="ServiceType">Type of serviec </param>
        /// <returns>Enumerable list of service statuses</returns>
        public IEnumerable <ENUM_SERVICE_STATUS_PROCESS> Refresh(SC_SERVICE_TYPE ServiceType)
        {
            // Quote from MSDN: Windows Server 2003 and Windows XP:
            // The maximum size of this array is 64K bytes. This limit
            // was increased as of Windows Server 2003 SP1 and Windows XP SP2.

            const int BytesAllocated = 63 * 1024;

            IntPtr lpServices       = Marshal.AllocHGlobal((int)BytesAllocated);
            int    cbBytesNeeded    = 0;
            int    ServicesReturned = 0;
            int    ResumeHandle     = 0;
            bool   repeat           = true;

            while (repeat)
            {
                if (NativeServiceFunctions.EnumServicesStatusEx(Handle,
                                                                SC_ENUM_TYPE.SC_ENUM_PROCESS_INFO,
                                                                ServiceType,
                                                                SC_QUERY_SERVICE_STATUS.SERVICE_STATE_ALL,
                                                                lpServices,
                                                                BytesAllocated,
                                                                ref cbBytesNeeded,
                                                                ref ServicesReturned,
                                                                ref ResumeHandle,
                                                                null))
                {
                    Log.InfoFormat("Got {0} services in last chunk", ServicesReturned);
                    repeat = false;
                }
                else
                {
                    int LastError = Marshal.GetLastWin32Error();
                    if (LastError == NativeServiceFunctions.ERROR_MORE_DATA)
                    {
                        Log.InfoFormat("Got {0} services in this chunk", ServicesReturned);
                    }
                    else
                    {
                        NativeHelpers.ReportFailure("EnumServicesStatusEx()");
                        break;
                    }
                }

                int iPtr = lpServices.ToInt32();
                for (int i = 0; i < ServicesReturned; i++)
                {
                    ENUM_SERVICE_STATUS_PROCESS essp = (ENUM_SERVICE_STATUS_PROCESS)
                                                       Marshal.PtrToStructure(
                        new IntPtr(iPtr),
                        typeof(ENUM_SERVICE_STATUS_PROCESS));

                    yield return(essp);

                    iPtr += Marshal.SizeOf(essp);
                }
            }
        }
示例#2
0
        public ServiceDataObject(NativeService service, ENUM_SERVICE_STATUS_PROCESS essp)
            :   base(essp.ServiceName)
        {
            DisplayName      = essp.DisplayName;
            CurrentState     = essp.CurrentState;
            ControlsAccepted = essp.ControlsAccepted;

            Win32ExitCode           = essp.Win32ExitCode.ToString();
            ServiceSpecificExitCode = essp.ServiceSpecificExitCode.ToString();
            CheckPoint   = essp.CheckPoint.ToString();
            WaitHint     = essp.WaitHint.ToString();
            ServiceFlags = essp.ServiceFlags.ToString();
            ServiceType  = essp.ServiceType;
            if (essp.ProcessID != 0)
            {
                PID = essp.ProcessID.ToString();
            }
            else
            {
                PID = "";
            }
            QUERY_SERVICE_CONFIG config = service.ServiceConfig;

            if (essp.CurrentState == SC_RUNTIME_STATUS.SERVICE_RUNNING)
            {
                IsRunning = true;
            }

            if (config != null)
            {
                if (config.StartType == SC_START_TYPE.SERVICE_DISABLED)
                {
                    IsDisabled = true;
                }
                StartType      = config.StartType;
                BinaryPathName = config.BinaryPathName;
                LoadOrderGroup = config.LoadOrderGroup;
                ErrorControl   = ServicesLocalisation.Localized(config.ErrorControl);
                TagId          = config.TagId.ToString();
                User           = config.ServiceStartName;
            }
            ToolTip                = Description = service.Description;
            ToolTipCaption         = DisplayName;
            ConstructionIsFinished = true;
        }
示例#3
0
        public ServiceDataObject(NativeService service, ENUM_SERVICE_STATUS_PROCESS essp)
            : base(essp.ServiceName)
        {
            DisplayName = essp.DisplayName;
            CurrentState = essp.CurrentState;
            ControlsAccepted = essp.ControlsAccepted;

            Win32ExitCode = essp.Win32ExitCode.ToString();
            ServiceSpecificExitCode = essp.ServiceSpecificExitCode.ToString();
            CheckPoint = essp.CheckPoint.ToString();
            WaitHint = essp.WaitHint.ToString();
            ServiceFlags = essp.ServiceFlags.ToString();
            ServiceType = essp.ServiceType;
            if (essp.ProcessID != 0)
                PID = essp.ProcessID.ToString();
            else
                PID = "";
            QUERY_SERVICE_CONFIG config = service.ServiceConfig;

            if (essp.CurrentState == SC_RUNTIME_STATUS.SERVICE_RUNNING)
            {
                IsRunning = true;
            }

            if (config != null)
            {
                if (config.StartType == SC_START_TYPE.SERVICE_DISABLED)
                {
                    IsDisabled = true;
                }
                StartType = config.StartType;
                BinaryPathName = config.BinaryPathName;
                LoadOrderGroup = config.LoadOrderGroup;
                ErrorControl = ServicesLocalisation.Localized(config.ErrorControl);
                TagId = config.TagId.ToString();
                User = config.ServiceStartName;

            }
            ToolTip = Description = service.Description;
            ToolTipCaption = DisplayName;
            ConstructionIsFinished = true;
        }
示例#4
0
 public void UpdateFrom(ENUM_SERVICE_STATUS_PROCESS essp)
 {
     CurrentState     = essp.CurrentState;
     ControlsAccepted = essp.ControlsAccepted;
     SetNonZeroStringProperty("PID", essp.ProcessID);
 }
示例#5
0
 public void UpdateFrom(ENUM_SERVICE_STATUS_PROCESS essp)
 {
     CurrentState = essp.CurrentState;
     ControlsAccepted = essp.ControlsAccepted;
     SetNonZeroStringProperty("PID", essp.ProcessID);
 }