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); } } }
private void UserControl_Unloaded(object sender, RoutedEventArgs e) { DisplayName = TbDisplayName.Text; Description = TbDescription.Text; BinaryPathName = TbImagePath.Text; StartType = (SC_START_TYPE)CbStartupType.SelectedIndex; }
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);
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 );
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); } }
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); }
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); }
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()); } }
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(); } }
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); } } } }
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); } } } }
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; }
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(); }
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);
private void OnApplyStartupChanges(SC_START_TYPE ExpectedStartType) { foreach (ServiceObject so in SelectedServices) { if (so.StartType != ExpectedStartType) { so.StartType = ExpectedStartType; so.ApplyChanges(); } } ServiceView.UpdateDisplay(); }
public ServiceActionTemplate(string id) { ID = id; StartType = SC_START_TYPE.SERVICE_NO_CHANGE; Name = ""; }
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; } }
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);
private void ApplySpecificAction(ServiceObject so, SC_START_TYPE st) { }