void SetValue(string path, string name, string value) { string act = ID; if (path != null) { act += "\\" + path; } if (value != null) { WCU.Ensure(act, true)[name] = value; } else { if (CU.HasKey(act) && CU.Open(act).HasValue(name)) { WCU.Open(act, true)[name] = null; } if (LM.HasKey(act) && LM.Open(act).HasValue(name)) { WLM.Open(act, true)[name] = null; } } }
/// <summary> /// Returns the startup mode for a service. /// </summary> /// <param name="serviceName">The service name.</param> /// <returns>The start mode.</returns> public static ServiceStartMode GetStartMode(string serviceName) { RegKey key; int raw; key = RegKey.Open(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\" + serviceName); if (key == null) { throw new InvalidOperationException(string.Format("Service [{0}] does not exist.", serviceName)); } key.Close(); raw = RegKey.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\" + serviceName + ":Start", 0); switch (raw) { case 2: return(ServiceStartMode.Automatic); case 3: return(ServiceStartMode.Manual); default: case 4: return(ServiceStartMode.Disabled); } }
/// <summary> /// Sets the startup mode for a service. /// </summary> /// <param name="serviceName">The service name.</param> /// <param name="mode">Thye new start mode.</param> public static void SetStartMode(string serviceName, ServiceStartMode mode) { RegKey key; int raw = 0; key = RegKey.Open(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\" + serviceName); if (key == null) { throw new InvalidOperationException(string.Format("Service [{0}] does not exist.", serviceName)); } key.Close(); switch (mode) { case ServiceStartMode.Automatic: raw = 2; break; case ServiceStartMode.Manual: raw = 3; break; case ServiceStartMode.Disabled: raw = 4; break; } if (raw != 0) { RegKey.SetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\" + serviceName + ":Start", raw); } }
public static void Clone(RegKey kf, RegKey kt) { foreach (string v in kf.Values) { kt[v] = kf[v]; } foreach (string k in kf.Keys) { Clone(kf.Open(k), kt.Ensure(k)); } }
public static void CloneExtension(string from, string to) { Clone(from, to); RegKey tuk = WFX.Ensure(to + "\\UserChoice"); RegKey fuk = FX.Open(from + "\\UserChoice"); if (fuk != null) { string pid = fuk["Progid"]; if (pid != null) { tuk["Progid"] = pid; } } }
public void RegKey_Open() { RegKey key; key = RegKey.Create(@"HKEY_LOCAL_MACHINE\Software\RegTest"); key.Set("Test1", "value1"); key.Close(); key = RegKey.Open(@"HKEY_LOCAL_MACHINE\Software\RegTest"); Assert.AreEqual("value1", key.Get("Test1")); key.Close(); RegKey.Delete(@"HKEY_LOCAL_MACHINE\Software\RegTest"); Assert.IsNull(RegKey.Open(@"HKEY_LOCAL_MACHINE\Software\RegTest")); }
string GetValue(string path, string name) { string act = ID; if (path != null) { act += "\\" + path; } RegKey k = CR.Open(act); if (k != null) { return(k[name]); } else { return(null); } }
public static void Clone(RegKey kf, RegKey kt) { foreach (string v in kf.Values) kt[v] = kf[v]; foreach (string k in kf.Keys) Clone(kf.Open(k), kt.Ensure(k)); }