Ejemplo n.º 1
0
        public override void ApplyTemplateInfo(ActionTemplateInfo ati, BackgroundAction action)
        {
            // default implementation: do nothing
            ServiceDataObject sdo = GetServiceDataObjectByID(ati.ID);

            if (sdo == null)
            {
                Log.ErrorFormat("Unable to find object for ID {0}", ati.ID);
            }
            else
            {
                string expectedStartType = ati["StartTypeString"];
                string actualStartType   = sdo.StartTypeString;
                if (expectedStartType != actualStartType)
                {
                    Log.InfoFormat("=> StartType for {0} needs to change from {1} to {2}",
                                   ati,
                                   actualStartType,
                                   expectedStartType);

                    using (NativeSCManager scm = new NativeSCManager(MachineName))
                    {
                        SC_START_TYPE startType = ServicesLocalisation.ReverseLocalizedStartType(expectedStartType);
                        if (startType != SC_START_TYPE.SERVICE_NO_CHANGE)
                        {
                            sdo.ApplyStartupChanges(scm, startType);
                        }
                    }
                }
                else
                {
                    Log.InfoFormat("=> StartType for {0} identical, no need to change", ati);
                }
            }
        }
Ejemplo n.º 2
0
 private void UserControl_Unloaded(object sender, RoutedEventArgs e)
 {
     DisplayName    = TbDisplayName.Text;
     Description    = TbDescription.Text;
     BinaryPathName = TbImagePath.Text;
     StartType      = (SC_START_TYPE)CbStartupType.SelectedIndex;
 }
Ejemplo n.º 3
0
 public static extern unsafe 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);
Ejemplo n.º 4
0
 private static extern IntPtr CreateService(IntPtr hSCManager,
                                            string lpServiceName,
                                            string lpDisplayName,
                                            SC_MANAGER_ACCESS dwDesiredAccess,
                                            SC_SERVICE_TYPE dwServiceType,
                                            SC_START_TYPE dwStartType,
                                            SC_ERROR_CONTROL dwErrorControl,
                                            string lpBinaryPathName,
                                            string lpLoadOrderGroup,
                                            IntPtr lpdwTagId,
                                            string lpDependencies,
                                            string lpServiceStartName,
                                            string lpPassword
                                            );
Ejemplo n.º 5
0
 private bool ApplyStartupChanges(SC_START_TYPE startupType)
 {
     using (new WaitCursor())
     {
         bool result = true;
         using (NativeSCManager scm = new NativeSCManager(MachineName))
         {
             foreach (ServiceDataObject sdo in MainListView.SelectedItems)
             {
                 if (!sdo.ApplyStartupChanges(scm, startupType))
                 {
                     result = false;
                 }
             }
         }
         return(result);
     }
 }
Ejemplo n.º 6
0
        public bool ApplyStartupChanges(NativeSCManager scm, SC_START_TYPE startupType)
        {
            bool success = true;

            if (startupType != StartType)
            {
                Log.InfoFormat("{0}: Change SC_START_TYPE from {1} to {2}", InternalID, StartType, startupType);
                using (NativeService ns = new NativeService(scm,
                                                            InternalID,
                                                            ACCESS_MASK.SERVICE_CHANGE_CONFIG | ACCESS_MASK.SERVICE_QUERY_STATUS))
                {
                    success = NativeServiceFunctions.ChangeServiceConfig(ns.Handle,
                                                                         StartType: startupType);
                    if (success)
                    {
                        StartType = startupType;
                    }
                }
            }
            return(success);
        }
Ejemplo n.º 7
0
        public void RevertChanges()
        {
            DisplayName    = TbDisplayName.Text = SDO.DisplayName;
            Description    = TbDescription.Text = SDO.Description;
            BinaryPathName = TbImagePath.Text = SDO.BinaryPathName;
            CbStartupType.SelectedIndex = (int)SDO.StartType;
            StartType = SDO.StartType;

            if (SDO.IsSystemAccount)
            {
                RbSystemAccount.IsChecked = true;
                RbSystemAccount_Click(null, null);
            }
            else
            {
                RbLogonAs.IsChecked = true;
                TbAccountName.Text  = SDO.User;
                RbLogonAs_Click(null, null);
            }

            BtInteractWithDesktop.IsChecked = ((SDO.ServiceType & SC_SERVICE_TYPE.SERVICE_INTERACTIVE_PROCESS) != 0);
        }
Ejemplo n.º 8
0
        public static string Localized(SC_START_TYPE st)
        {
            switch (st)
            {
            case SC_START_TYPE.SERVICE_AUTO_START:
                return(pserv4.Properties.Resources.SERVICE_AUTO_START);

            case SC_START_TYPE.SERVICE_BOOT_START:
                return(pserv4.Properties.Resources.SERVICE_BOOT_START);

            case SC_START_TYPE.SERVICE_DEMAND_START:
                return(pserv4.Properties.Resources.SERVICE_DEMAND_START);

            case SC_START_TYPE.SERVICE_DISABLED:
                return(pserv4.Properties.Resources.SERVICE_DISABLED);

            case SC_START_TYPE.SERVICE_SYSTEM_START:
                return(pserv4.Properties.Resources.SERVICE_SYSTEM_START);

            default:
                return(st.ToString());
            }
        }
Ejemplo n.º 9
0
        public static string Localized(SC_START_TYPE st)
        {
            switch (st)
            {
                case SC_START_TYPE.SERVICE_AUTO_START:
                    return pserv4.Properties.Resources.SERVICE_AUTO_START;

                case SC_START_TYPE.SERVICE_BOOT_START:
                    return pserv4.Properties.Resources.SERVICE_BOOT_START;

                case SC_START_TYPE.SERVICE_DEMAND_START:
                    return pserv4.Properties.Resources.SERVICE_DEMAND_START;

                case SC_START_TYPE.SERVICE_DISABLED:
                    return pserv4.Properties.Resources.SERVICE_DISABLED;

                case SC_START_TYPE.SERVICE_SYSTEM_START:
                    return pserv4.Properties.Resources.SERVICE_SYSTEM_START;

                default:
                    return st.ToString();
            }
        }
Ejemplo n.º 10
0
        public void ApplyChanges(
            NativeSCManager scm,
            SC_START_TYPE startupType,
            string displayName,
            string binaryPathName,
            string description)
        {
            using (NativeService ns = new NativeService(scm,
                                                        InternalID,
                                                        ACCESS_MASK.SERVICE_CHANGE_CONFIG | ACCESS_MASK.SERVICE_QUERY_STATUS))
            {
                bool success = NativeServiceFunctions.ChangeServiceConfig(ns.Handle,
                                                                          StartType: startupType,
                                                                          DisplayName: displayName,
                                                                          BinaryPathName: binaryPathName);
                if (success)
                {
                    StartType = startupType;
                    if (displayName != null)
                    {
                        SetStringProperty("DisplayName", displayName);
                    }
                    if (binaryPathName != null)
                    {
                        SetStringProperty("BinaryPathName", binaryPathName);
                        NotifyPropertyChanged("InstallLocation");
                    }

                    if ((description != null) && !description.Equals(Description))
                    {
                        ns.Description = description;
                        SetStringProperty("Description", description);
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public void ApplyChanges(
            NativeSCManager scm,
            SC_START_TYPE startupType,
            string displayName,
            string binaryPathName,
            string description)
        {
            using (NativeService ns = new NativeService(scm,
                InternalID,
                ACCESS_MASK.SERVICE_CHANGE_CONFIG | ACCESS_MASK.SERVICE_QUERY_STATUS))
            {
                bool success = NativeServiceFunctions.ChangeServiceConfig(ns.Handle,
                    StartType: startupType,
                    DisplayName: displayName,
                    BinaryPathName: binaryPathName);
                if (success)
                {
                    StartType = startupType;
                    if( displayName != null )
                    {
                        SetStringProperty("DisplayName", displayName);
                    }
                    if( binaryPathName != null )
                    {
                        SetStringProperty("BinaryPathName", binaryPathName);
                        NotifyPropertyChanged("InstallLocation");
                    }

                    if ((description != null) && !description.Equals(Description))
                    {
                        ns.Description = description;
                        SetStringProperty("Description", description);
                    }
                }
            }
        }
Ejemplo n.º 12
0
 public bool ApplyStartupChanges(NativeSCManager scm, SC_START_TYPE startupType)
 {
     bool success = true;
     if (startupType != StartType)
     {
         Log.InfoFormat("{0}: Change SC_START_TYPE from {1} to {2}", InternalID, StartType, startupType);
         using (NativeService ns = new NativeService(scm,
             InternalID,
             ACCESS_MASK.SERVICE_CHANGE_CONFIG | ACCESS_MASK.SERVICE_QUERY_STATUS))
         {
             success = NativeServiceFunctions.ChangeServiceConfig(ns.Handle,
                 StartType: startupType);
             if( success )
             {
                 StartType = startupType;
             }
         }
     }
     return success;
 }
Ejemplo n.º 13
0
 internal static string DescribeStartType(SC_START_TYPE s)
 {
     switch (s)
     {
         case SC_START_TYPE.SERVICE_AUTO_START:
             return IDS.SERVICE_AUTO_START;
         case SC_START_TYPE.SERVICE_BOOT_START:
             return IDS.SERVICE_BOOT_START;
         case SC_START_TYPE.SERVICE_DEMAND_START:
             return IDS.SERVICE_DEMAND_START;
         case SC_START_TYPE.SERVICE_DISABLED:
             return IDS.SERVICE_DISABLED;
         case SC_START_TYPE.SERVICE_SYSTEM_START:
             return IDS.SERVICE_SYSTEM_START;
     }
     return s.ToString();
 }
Ejemplo n.º 14
0
 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);
Ejemplo n.º 15
0
 private void OnApplyStartupChanges(SC_START_TYPE ExpectedStartType)
 {
     foreach (ServiceObject so in SelectedServices)
     {
         if (so.StartType != ExpectedStartType)
         {
             so.StartType = ExpectedStartType;
             so.ApplyChanges();
         }
     }
     ServiceView.UpdateDisplay();
 }
Ejemplo n.º 16
0
 public ServiceActionTemplate(string id)
 {
     ID = id;
     StartType = SC_START_TYPE.SERVICE_NO_CHANGE;
     Name = "";
 }
Ejemplo n.º 17
0
 private void UserControl_Unloaded(object sender, RoutedEventArgs e)
 {
     DisplayName = TbDisplayName.Text;
     Description = TbDescription.Text;
     BinaryPathName = TbImagePath.Text;
     StartType = (SC_START_TYPE)CbStartupType.SelectedIndex;
 }
Ejemplo n.º 18
0
 private bool ApplyStartupChanges(SC_START_TYPE startupType)
 {
     using (new WaitCursor())
     {
         bool result = true;
         using (NativeSCManager scm = new NativeSCManager(MachineName))
         {
             foreach (ServiceDataObject sdo in MainListView.SelectedItems)
             {
                 if( !sdo.ApplyStartupChanges(scm, startupType) )
                 {
                     result = false;
                 }
             }
         }
         return result;
     }
 }
Ejemplo n.º 19
0
        public void RevertChanges()
        {
            DisplayName = TbDisplayName.Text = SDO.DisplayName;
            Description = TbDescription.Text = SDO.Description;
            BinaryPathName = TbImagePath.Text = SDO.BinaryPathName;
            CbStartupType.SelectedIndex = (int)SDO.StartType;
            StartType = SDO.StartType;

            if (SDO.IsSystemAccount)
            {
                RbSystemAccount.IsChecked = true;
                RbSystemAccount_Click(null, null);
            }
            else
            {
                RbLogonAs.IsChecked = true;
                TbAccountName.Text = SDO.User;
                RbLogonAs_Click(null, null);
            }

            BtInteractWithDesktop.IsChecked = ((SDO.ServiceType & SC_SERVICE_TYPE.SERVICE_INTERACTIVE_PROCESS) != 0);
        }
Ejemplo n.º 20
0
 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);
Ejemplo n.º 21
0
 private void ApplySpecificAction(ServiceObject so, SC_START_TYPE st)
 {
 }