public NativeService(NativeSCManager scm, string ServiceName) { Handle = NativeServiceFunctions.OpenService( scm.Handle, ServiceName, (uint)(ACCESS_MASK.STANDARD_RIGHTS_READ | ACCESS_MASK.GENERIC_READ)); }
public NativeService(NativeSCManager scm, string ServiceName, ACCESS_MASK am) { Handle = NativeServiceFunctions.OpenService( scm.Handle, ServiceName, (uint)am); }
private bool CanConnect(string name) { try { using (Services.NativeSCManager scm = new Services.NativeSCManager(name)) { return true; } } catch(Exception e) { GSharpTools.Tools.DumpException(e, "unable to connect to {0}", name); } return false; }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs args) { if (Services.Count > 0) { CurrentPercentage = 0.0; PercentPerService = 100.0 / Services.Count; ACCESS_MASK ServiceAccessMask = SSR.GetServiceAccessMask() | ACCESS_MASK.STANDARD_RIGHTS_READ | ACCESS_MASK.SERVICE_QUERY_STATUS; using (SCM = new NativeSCManager()) { int ServiceIndex = 0; foreach (ServiceObject so in Services) { try { Trace.TraceInformation("Invoke StatusMessage '{0}', {1}", so, so.CurrentState); Invoke(new StatusMessageDelegate(StatusMessage), so, so.CurrentState); CurrentPercentage = ServiceIndex * (100.0 / Services.Count); using (NativeService ns = new NativeService(SCM, so.GetText((int)ServiceItemTypes.ServiceName), ServiceAccessMask)) { backgroundWorker1_Process(ns, so); } ++ServiceIndex; } catch (Exception e) { GSharpTools.Tools.DumpException(e, "ChangeServiceStatus.backgroundWorker1_DoWork"); } if (bCancelled) break; } } } //backgroundWorker1.ReportProgress(100); }
public void Uninstall() { using (NativeSCManager SCM = new NativeSCManager()) { using (NativeService ns = new NativeService(SCM, ServiceName, ACCESS_MASK.STANDARD_RIGHTS_REQUIRED)) { NativeServiceFunctions.DeleteService(ns.Handle); } } }
public void RefreshConfig(NativeSCManager scm) { using (NativeService ns = new NativeService(scm, ServiceName)) { Config = ns.ServiceConfig; Objects[(int)ServiceItemTypes.Start] = NativeServiceFunctions.DescribeStartType(Config.StartType); Objects[(int)ServiceItemTypes.Path] = Config.BinaryPathName; Objects[(int)ServiceItemTypes.LoadOrderGroup] = Config.LoadOrderGroup; Objects[(int)ServiceItemTypes.Type] = DescribeServiceType(Config.ServiceType); Objects[(int)ServiceItemTypes.ErrorControl] = NativeServiceFunctions.DescribeErrorControl(Config.ErrorControl); Objects[(int)ServiceItemTypes.TagId] = Config.TagId.ToString(); Objects[(int)ServiceItemTypes.Dependencies] = Config.Dependencies; Objects[(int)ServiceItemTypes.Description] = ns.Description; Objects[(int)ServiceItemTypes.User] = Config.ServiceStartName; DescriptionText = ns.Description; if (Config.StartType == SC_START_TYPE.SERVICE_DISABLED) { ForegroundColor = Color.Gray; } } }
public bool ApplyChanges() { if (!Modified) return true; bool success = true; using (NativeSCManager SCM = new NativeSCManager()) { using (NativeService ns = new NativeService(SCM, ServiceName, ACCESS_MASK.SERVICE_CHANGE_CONFIG | ACCESS_MASK.SERVICE_QUERY_STATUS)) { success = NativeServiceFunctions.ChangeServiceConfig(ns.Handle, ServiceTypeModified ? Config.ServiceType : SC_SERVICE_TYPE.SERVICE_NO_CHANGE, StartTypeModified ? Config.StartType : SC_START_TYPE.SERVICE_NO_CHANGE, ErrorControlModified ? Config.ErrorControl : SC_ERROR_CONTROL.SERVICE_NO_CHANGE, BinaryPathNameModified ? Config.BinaryPathName : null, LoadOrderGroupModified ? Config.LoadOrderGroup : null, null, null, ServiceStartNameModified ? Config.ServiceStartName : null, PasswordModified ? PasswordText : null, DisplayNameModified ? DisplayName : null); if (success) { if (DescriptionModified) { SERVICE_DESCRIPTION sd = new SERVICE_DESCRIPTION(); sd.Description = DescriptionText; const int cbBufSize = 8 * 1024; IntPtr lpMemory = Marshal.AllocHGlobal((int)cbBufSize); Marshal.StructureToPtr(sd, lpMemory, false); NativeServiceFunctions.ChangeServiceConfig2(ns.Handle, SC_SERVICE_CONFIG.SERVICE_CONFIG_DESCRIPTION, lpMemory); Marshal.FreeHGlobal(lpMemory); } } Modified = false; RefreshConfig(SCM); } } return success; }
public void Refresh(List<IServiceObject> Services, SC_SERVICE_TYPE ServiceType) { using (NativeSCManager scm = new NativeSCManager()) { scm.Refresh(Services, ServiceType); } }