/// <summary> /// Open an instance of the SCM. /// </summary> /// <param name="machine_name">The machine name for the SCM.</param> /// <param name="database_name">The database name. Specify SERVICES_ACTIVE_DATABASE or SERVICES_FAILED_DATABASE. /// If null then SERVICES_ACTIVE_DATABASE is used.</param> /// <param name="desired_access">The desired access for the SCM connection.</param> /// <param name="throw_on_error">True to throw on error.</param> /// <returns>The SCM instance.</returns> public static NtResult <ServiceControlManager> Open(string machine_name, string database_name, ServiceControlManagerAccessRights desired_access, bool throw_on_error) { if (machine_name == string.Empty) { machine_name = null; } if (database_name == string.Empty) { database_name = null; } SafeServiceHandle scm = Win32NativeMethods.OpenSCManager(machine_name, database_name, desired_access); if (!scm.IsInvalid) { return(new ServiceControlManager(scm, machine_name, desired_access).CreateResult()); } return(Win32Utils.CreateResultFromDosError <ServiceControlManager>(throw_on_error)); }