/// <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); } }
public void RegKey_Basic() { RegKey key; Assert.IsFalse(RegKey.Exists(@"HKEY_LOCAL_MACHINE\Software\RegTest")); key = RegKey.Create(@"HKEY_LOCAL_MACHINE\Software\RegTest"); Assert.IsTrue(RegKey.Exists(@"HKEY_LOCAL_MACHINE\Software\RegTest")); key.Set("Test1", "value1"); key.Set("Test2", "value2"); key.Set("Test3", 3); Assert.AreEqual("value1", key.Get("Test1")); Assert.AreEqual("value2", key.Get("Test2")); Assert.AreEqual("3", key.Get("Test3")); key.Set("Test1", "hello"); Assert.AreEqual("hello", key.Get("Test1")); Assert.AreEqual("default", key.Get("foobar", "default")); key.Close(); Assert.AreEqual("hello", RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test1")); Assert.AreEqual("value2", RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test2")); Assert.AreEqual("3", RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test3")); RegKey.SetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test4", "Hello"); Assert.AreEqual("Hello", RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test4")); RegKey.Delete(@"HKEY_LOCAL_MACHINE\Software\RegTest"); }
public void RegKey_DeleteValue() { RegKey key; key = RegKey.Create(@"HKEY_LOCAL_MACHINE\Software\RegTest"); key.Set("Test1", "10"); key.Set("Test2", "20"); Assert.AreEqual("20", key.Get("Test2")); key.DeleteValue("Test2"); Assert.IsNull(key.Get("Test2")); key.Close(); RegKey.Delete(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test1"); Assert.IsNull(key.Get("Test1")); RegKey.Delete(@"HKEY_LOCAL_MACHINE\Software\RegTest"); RegKey.SetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Foo", "test"); Assert.AreEqual("test", RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Foo")); RegKey.Delete(@"HKEY_LOCAL_MACHINE\Software\RegTest"); }
public void RegKey_SetGet_TimeSpan() { RegKey key; key = RegKey.Create(@"HKEY_LOCAL_MACHINE\Software\RegTest"); key.Set("TS1", "10"); key.Set("TS2", "10ms"); key.Set("TS3", "hello?"); Assert.AreEqual(TimeSpan.FromSeconds(10), key.Get("TS1", TimeSpan.FromSeconds(55))); Assert.AreEqual(TimeSpan.FromMilliseconds(10), key.Get("TS2", TimeSpan.FromSeconds(55))); Assert.AreEqual(TimeSpan.FromSeconds(55), key.Get("TS3", TimeSpan.FromSeconds(55))); key.Close(); Assert.AreEqual(TimeSpan.FromSeconds(10), RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:TS1", TimeSpan.FromSeconds(55))); Assert.AreEqual(TimeSpan.FromMilliseconds(10), RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:TS2", TimeSpan.FromSeconds(55))); Assert.AreEqual(TimeSpan.FromSeconds(55), RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:TS3", TimeSpan.FromSeconds(55))); Assert.AreEqual(TimeSpan.FromSeconds(55), RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:TS4", TimeSpan.FromSeconds(55))); RegKey.SetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:TS5", TimeSpan.FromSeconds(1001)); Assert.AreEqual(TimeSpan.FromSeconds(1001), RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:TS5", TimeSpan.FromSeconds(1))); RegKey.Delete(@"HKEY_LOCAL_MACHINE\Software\RegTest"); }
public void RegKey_SetGet_Int() { RegKey key; key = RegKey.Create(@"HKEY_LOCAL_MACHINE\Software\RegTest"); key.Set("Int1", 0); key.Set("Int2", 100); key.Set("Int3", "-100"); key.Set("Int4", "what???"); Assert.AreEqual(0, key.Get("Int1", 55)); Assert.AreEqual(100, key.Get("Int2", 55)); Assert.AreEqual(-100, key.Get("Int3", 55)); Assert.AreEqual(55, key.Get("Int4", 55)); Assert.AreEqual(55, key.Get("Int5", 55)); key.Close(); Assert.AreEqual(0, RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Int1", 55)); Assert.AreEqual(100, RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Int2", 55)); Assert.AreEqual(-100, RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Int3", 55)); Assert.AreEqual(55, RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Int4", 55)); Assert.AreEqual(55, RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Int5", 55)); RegKey.SetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Int6", 1001); Assert.AreEqual(1001, RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Int6", 0)); RegKey.Delete(@"HKEY_LOCAL_MACHINE\Software\RegTest"); }
public override void PlayTitleInternal(string executablePath, string discPath, int title) { string version = RegKey.GetValue("Version") as string; string arguments; if (version.StartsWith("1")) { arguments = "DVD://\"" + discPath + "\\\"@" + title; } else { arguments = "dvd:///\"" + discPath + "\\\"#" + title; } var process = new Process(); process.StartInfo = new ProcessStartInfo { FileName = executablePath, Arguments = arguments }; process.Start(); }
/// <summary> /// Restores the state to before the installation. /// </summary> /// <param name="state">The installer state.</param> private void Restore(IDictionary state) { try { string keyPath = (string)state[InstallTools.GetStateKey(this, "KeyPath")]; object orgValue = state[InstallTools.GetStateKey(this, "OrgValue")]; if (orgValue == null) { RegKey.Delete(keyPath); } else if (orgValue is int) { RegKey.SetValue(keyPath, (int)orgValue); } else if (orgValue is string) { RegKey.GetValue(keyPath, (string)orgValue); } else { throw new InvalidOperationException("RegInstaller works only for REG_DWORD and REG_SZ registry values."); } } catch { // I'm going to ignore errors here since it'll often be the case // that the parent key has already been removed. } }
public void RegKey_SetGet_Bool() { RegKey key; key = RegKey.Create(@"HKEY_LOCAL_MACHINE\Software\RegTest"); key.Set("Bool1", true); key.Set("Bool2", false); key.Set("Bool3", "yes"); key.Set("Bool4", "no"); key.Set("Bool5", "on"); key.Set("Bool6", "off"); key.Set("Bool7", 1); key.Set("Bool8", 0); key.Set("Bool9", "what the hell?"); Assert.IsTrue(key.Get("Bool1", false)); Assert.IsFalse(key.Get("Bool2", true)); Assert.IsTrue(key.Get("Bool3", false)); Assert.IsFalse(key.Get("Bool4", true)); Assert.IsTrue(key.Get("Bool5", false)); Assert.IsFalse(key.Get("Bool6", true)); Assert.IsTrue(key.Get("Bool7", false)); Assert.IsFalse(key.Get("Bool8", true)); Assert.IsTrue(key.Get("Bool9", true)); Assert.IsFalse(key.Get("Bool9", false)); Assert.IsTrue(key.Get("Bool10", true)); Assert.IsFalse(key.Get("Bool10", false)); key.Close(); Assert.IsTrue(RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Bool1", false)); Assert.IsFalse(RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Bool2", true)); Assert.IsTrue(RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Bool3", false)); Assert.IsFalse(RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Bool4", true)); Assert.IsTrue(RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Bool5", false)); Assert.IsFalse(RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Bool6", true)); Assert.IsTrue(RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Bool7", false)); Assert.IsFalse(RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Bool8", true)); Assert.IsTrue(RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Bool9", true)); Assert.IsFalse(RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Bool9", false)); Assert.IsTrue(RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Bool10", true)); Assert.IsFalse(RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Bool10", false)); RegKey.SetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Bool11", true); Assert.IsTrue(RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Bool11", false)); RegKey.Delete(@"HKEY_LOCAL_MACHINE\Software\RegTest"); }
public void RegKey_REG_DWORD() { RegKey key; key = RegKey.Create(@"HKEY_LOCAL_MACHINE\Software\RegTest"); key.SetDWORD("Test1", 10); Assert.AreEqual("10", key.Get("Test1")); key.Close(); RegKey.SetDWORDValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test2", 20); Assert.AreEqual("20", RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test2")); RegKey.Delete(@"HKEY_LOCAL_MACHINE\Software\RegTest"); }
private void Awake() { string keyPath = "SOFTWARE\\" + "BuildingSimulator" + "\\Settings"; // путь в регистре до настроек RegKey.GetValue("LoadWorld", out string loadWrld, keyPath); // получаем название мира loadWrld = SHA1_Encode.Decryption(loadWrld, "z0s%b&I)Y%PW26A8"); // декодируем название мира string path = Directory.GetCurrentDirectory() + "\\Saves\\" + loadWrld + ".txt"; // ищем такой же мир в папке Saves string[] save = File.ReadAllLines(path); //читаем найденое сохранение string count = SHA1_Encode.Decryption(save[1], "z0s%b&I)Y%PW26A8"); // декодируем // Debug.Log("Chunks count - " + count); string isFp = SHA1_Encode.Decryption(save[5], "z0s%b&I)Y%PW26A8"); bool isFirstGame = System.Convert.ToBoolean(isFp); BuildPlatforms(System.Convert.ToInt16(count), isFirstGame); }
/// <summary> /// Installs the registry key. /// </summary> /// <param name="state">The installer state.</param> public override void Install(IDictionary state) { object orgValue; base.Install(state); switch (RegKey.GetValueType(keyPath)) { case WinApi.REG_NONE: orgValue = null; break; case WinApi.REG_DWORD: orgValue = RegKey.GetValue(keyPath, 0); break; case WinApi.REG_SZ: orgValue = RegKey.GetValue(keyPath, string.Empty); break; default: throw new InvalidOperationException("RegInstaller works only for REG_DWORD and REG_SZ registry values."); } state[InstallTools.GetStateKey(this, "KeyPath")] = keyPath; state[InstallTools.GetStateKey(this, "OrgValue")] = orgValue; if (strValue != null) { RegKey.SetValue(keyPath, strValue); } else { RegKey.SetValue(keyPath, intValue); } }
public void InstallTools_RegInstaller() { // $todo(jeff.lill): I need to come up with a better test harness for this #if FALSE Hashtable state = new Hashtable(); RegInstaller installer; installer = new RegInstaller(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test1", 10); installer.Install(state); Assert.AreEqual(10, RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test1", 0)); installer.Commit(state); Assert.AreEqual(10, RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test1", 0)); installer.Uninstall(state); Assert.AreEqual(WinApi.REG_NONE, RegKey.GetValueType(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test1")); installer = new RegInstaller(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test1", 10); installer.Install(state); Assert.AreEqual(10, RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test1", 0)); installer.Rollback(state); Assert.AreEqual(WinApi.REG_NONE, RegKey.GetValueType(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test1")); #else Assert.Inconclusive("Test Disabled"); #endif }