Beispiel #1
0
        public static string Localized(SC_SERVICE_TYPE st)
        {
            if( SC_SERVICE_TYPES == null )
            {
                SC_SERVICE_TYPES = new Dictionary<SC_SERVICE_TYPE,string>();
                SC_SERVICE_TYPES[SC_SERVICE_TYPE.SERVICE_KERNEL_DRIVER] = pserv4.Properties.Resources.SERVICE_KERNEL_DRIVER;
                SC_SERVICE_TYPES[SC_SERVICE_TYPE.SERVICE_WIN32_OWN_PROCESS] = pserv4.Properties.Resources.SERVICE_WIN32_OWN_PROCESS;
                SC_SERVICE_TYPES[SC_SERVICE_TYPE.SERVICE_WIN32_SHARE_PROCESS] = pserv4.Properties.Resources.SERVICE_WIN32_SHARE_PROCESS;
                SC_SERVICE_TYPES[SC_SERVICE_TYPE.SERVICE_FILE_SYSTEM_DRIVER] = pserv4.Properties.Resources.SERVICE_FILE_SYSTEM_DRIVER;
                SC_SERVICE_TYPES[SC_SERVICE_TYPE.SERVICE_KERNEL_DRIVER] = pserv4.Properties.Resources.SERVICE_KERNEL_DRIVER;
            }
            StringBuilder result = new StringBuilder();
            bool first = true;
            foreach(SC_SERVICE_TYPE k in SC_SERVICE_TYPES.Keys )
            {
                if ((st & k) != 0)
                {
                    st &= ~(k);
                    if (first)
                        first = false;
                    else
                        result.Append('|');

                    result.Append(SC_SERVICE_TYPES[k]);
                    if (st == 0)
                        break;
                }
            }
            return result.ToString();
        }
Beispiel #2
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);
                }
            }
        }
Beispiel #3
0
        public void Refresh(List<IServiceObject> Services, 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;

            while (true)
            {
                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))
                {
                    Trace.TraceInformation("Got {0} services in last chunk", ServicesReturned);
                    Refresh(Services, lpServices, ServicesReturned);
                    break;
                }
                else
                {
                    int LastError = Marshal.GetLastWin32Error();
                    if (LastError == NativeServiceFunctions.ERROR_MORE_DATA)
                    {
                        Trace.TraceInformation("Got {0} services in this chunk", ServicesReturned);
                        Refresh(Services, lpServices, ServicesReturned);
                    }
                    else
                    {
                        Trace.TraceInformation("ERROR {0}, unable to query list", LastError);
                        break;
                    }
                }
            }
        }
        public ServicesController(ListView listView)
            : base(listView)
        {
            MachineName = null; // localhost
            ServicesType = SC_SERVICE_TYPE.SERVICE_WIN32;

            Columns.Add(new StandardColumn(
                IDS.Services_Column_DisplayName,
                (int)ServiceItemTypes.DisplayName));
            Columns.Add(new StandardColumn(
                IDS.Services_Column_ServiceName,
                (int)ServiceItemTypes.ServiceName));
            Columns.Add(new StandardColumn(
                IDS.Services_Column_Status,
                (int)ServiceItemTypes.Status));
            Columns.Add(new StandardColumn(
                IDS.Services_Column_Start,
                (int)ServiceItemTypes.Start));
            Columns.Add(new StandardColumn(
                IDS.Services_Column_Type,
                (int)ServiceItemTypes.Type));
            Columns.Add(new StandardColumn(
                IDS.Services_Column_Path,
                (int)ServiceItemTypes.Path));
            Columns.Add(new StandardColumn_Int(
                IDS.Services_Column_PID,
                (int)ServiceItemTypes.PID));
            Columns.Add(new StandardColumn(
                IDS.Services_Column_User,
                (int)ServiceItemTypes.User));
            Columns.Add(new StandardColumn(
                IDS.Services_Column_LoadOrderGroup,
                (int)ServiceItemTypes.LoadOrderGroup));
            Columns.Add(new StandardColumn(
                IDS.Services_Column_ErrorControl,
                (int)ServiceItemTypes.ErrorControl));
            Columns.Add(new StandardColumn(
                IDS.Services_Column_TagId,
                (int)ServiceItemTypes.TagId));
            Columns.Add(new StandardColumn(
                IDS.Services_Column_Dependencies,
                (int)ServiceItemTypes.Dependencies));
            Columns.Add(new StandardColumn(
                IDS.Services_Column_Description,
                (int)ServiceItemTypes.Description));
        }
 public ServicesDataController(
     SC_SERVICE_TYPE servicesType = SC_SERVICE_TYPE.SERVICE_WIN32_OWN_PROCESS | SC_SERVICE_TYPE.SERVICE_WIN32_SHARE_PROCESS,
     string controllerName = "Services",
     string itemName = "Service",
     string controlStartDescription = null,
     string controlStopDescription =  null,
     string controlRestartDescription =  null,
     string controlPauseDescription =  null,
     string controlContinueDescription = null
     )
     : base(controllerName, 
             itemName,
             _(controlStartDescription, Resources.SERVICES_CTRL_START_Description),
             _(controlStopDescription, Resources.SERVICES_CTRL_STOP_Description),
             _(controlRestartDescription,Resources.SERVICES_CTRL_RESTART_Description),
             _(controlPauseDescription,Resources.SERVICES_CTRL_PAUSE_Description),
             _(controlContinueDescription,Resources.SERVICES_CTRL_CONTINUE_Description))
 {
     Caption = string.Format(Resources.IDS_SERVICES_CAPTION_LOCAL_MACHINE, ControllerName, Environment.MachineName);
     ServicesType = servicesType;
     HasProperties = true;
     MachineName = Environment.MachineName;
 }
 public static extern bool EnumServicesStatusEx(
     IntPtr hSCManager,
     SC_ENUM_TYPE InfoLevel,
     SC_SERVICE_TYPE ServiceType,
     SC_QUERY_SERVICE_STATUS ServiceState,
     IntPtr lpServices,
     int cbBufSize,
     ref int pcbBytesNeeded,
     ref int lpServicesReturned,
     ref int lpResumeHandle,
     string pszGroupName);
 public static unsafe extern bool ChangeServiceConfig(
     IntPtr serviceHandle,
     SC_SERVICE_TYPE ServiceType = SC_SERVICE_TYPE.SERVICE_NO_CHANGE,
     SC_START_TYPE StartType = SC_START_TYPE.SERVICE_NO_CHANGE,
     SC_ERROR_CONTROL ErrorControl = SC_ERROR_CONTROL.SERVICE_NO_CHANGE,
     string BinaryPathName = null,
     string LoadOrderGroup = null,
     string TagId = null,
     string Dependencies = null,
     string ServiceStartName = null,
     string Password = null,
     string DisplayName = null);
Beispiel #8
0
        public static string DescribeServiceType(SC_SERVICE_TYPE type)
        {
            StringBuilder result = new StringBuilder();
            bool first = true;

            if (ServiceTypeStrings == null)
            {
                ServiceTypeStrings = new Dictionary<SC_SERVICE_TYPE, string>();
                ServiceTypeStrings[SC_SERVICE_TYPE.SERVICE_DRIVER] = IDS.SERVICE_DRIVER;
                ServiceTypeStrings[SC_SERVICE_TYPE.SERVICE_WIN32] = IDS.SERVICE_WIN32;
                ServiceTypeStrings[SC_SERVICE_TYPE.SERVICE_FILE_SYSTEM_DRIVER] = IDS.SERVICE_FILE_SYSTEM_DRIVER;
                ServiceTypeStrings[SC_SERVICE_TYPE.SERVICE_KERNEL_DRIVER] = IDS.SERVICE_KERNEL_DRIVER;
                ServiceTypeStrings[SC_SERVICE_TYPE.SERVICE_WIN32_OWN_PROCESS] = IDS.SERVICE_WIN32_OWN_PROCESS;
                ServiceTypeStrings[SC_SERVICE_TYPE.SERVICE_WIN32_SHARE_PROCESS] = IDS.SERVICE_WIN32_SHARE_PROCESS;
                ServiceTypeStrings[SC_SERVICE_TYPE.SERVICE_INTERACTIVE_PROCESS] = IDS.SERVICE_INTERACTIVE_PROCESS;
            }

            foreach(SC_SERVICE_TYPE bitmask in ServiceTypeStrings.Keys)
            {
                if ((type & bitmask) != 0)
                {
                    if (first)
                        first = false;
                    else
                        result.Append("|");

                    result.Append(ServiceTypeStrings[bitmask]);
                }
            }

            return result.ToString();
        }
 public void Refresh(List<IServiceObject> Services, SC_SERVICE_TYPE ServiceType)
 {
     using (NativeSCManager scm = new NativeSCManager())
     {
         scm.Refresh(Services, ServiceType);
     }
 }
 public static unsafe extern bool ChangeServiceConfig(
     IntPtr serviceHandle,
     SC_SERVICE_TYPE ServiceType,
     SC_START_TYPE StartType,
     SC_ERROR_CONTROL ErrorControl,
     string BinaryPathName,
     string LoadOrderGroup,
     string TagId,
     string Dependencies,
     string ServiceStartName,
     string Password,
     string DisplayName);