public string GetExeFile() { string steamPath = RegistryEx.Read(@"SOFTWARE\Valve\Steam\SteamPath", ""); string exe = Path.Combine(steamPath, "steam.exe"); return(File.Exists(exe) ? Path.GetFullPath(exe) : null); }
private void LoadItems(bool isReference) { using (var shellKey = RegistryEx.GetRegistryKey(ShellPath)) { foreach (string itemName in shellKey.GetSubKeyNames()) { if (Filter != null && !Filter(itemName)) { continue; } string regPath = $@"{ShellPath}\{itemName}"; StoreShellItem item = new StoreShellItem(regPath, isReference); item.SelectedChanged += () => { foreach (StoreShellItem shellItem in list.Controls) { if (!shellItem.IsSelected) { chkSelectAll.Checked = false; return; } } chkSelectAll.Checked = true; }; list.AddItem(item); } } }
private void AddNewItem() { using (var shellKey = RegistryEx.GetRegistryKey(ShellPath, true, true)) { string keyName = ItemText.Replace("\\", "").Trim(); NewItemRegPath = ObjectPath.GetNewPathWithIndex($@"{ShellPath}\{keyName}", ObjectPath.PathType.Registry); keyName = RegistryEx.GetKeyName(NewItemRegPath); using (var key = shellKey.CreateSubKey(keyName, true)) { key.SetValue("MUIVerb", ItemText); if (rdoMulti.Checked) { key.SetValue("SubCommands", ""); } else { if (!string.IsNullOrWhiteSpace(ItemCommand)) { key.CreateSubKey("command", true).SetValue("", ItemCommand); } } } } }
public string GetJavaSdkDirectory() { string subkey = @"SOFTWARE\JavaSoft\Java Development Kit"; LogMessage("Looking for Java SDK.."); // Look for the registry keys written by the Java SDK installer foreach (var wow64 in new[] { RegistryEx.Wow64.Key32, RegistryEx.Wow64.Key64 }) { string key_name = string.Format(@"{0}\{1}\{2}", "HKLM", subkey, "CurrentVersion"); var currentVersion = RegistryEx.GetValueString(RegistryEx.LocalMachine, subkey, "CurrentVersion", wow64); if (!string.IsNullOrEmpty(currentVersion)) { LogMessage(" Key {0} found: {1}.", key_name, currentVersion); if (CheckRegistryKeyForExecutable(RegistryEx.LocalMachine, subkey + "\\" + currentVersion, "JavaHome", wow64, "bin", "jarsigner.exe")) { return(RegistryEx.GetValueString(RegistryEx.LocalMachine, subkey + "\\" + currentVersion, "JavaHome", wow64)); } } LogMessage(" Key {0} not found.", key_name); } // We ran out of things to check.. return(null); }
public string FindGame(IList <string> errors = null) { string steamPath = RegistryEx.Read <string>(@"Software\\Valve\\Steam\SteamPath"); if (string.IsNullOrEmpty(steamPath)) { errors?.Add("It appears you don't have Steam installed."); return(null); } string appsPath = Path.Combine(steamPath, "steamapps"); if (File.Exists(Path.Combine(appsPath, $"appmanifest_{GameInfo.Subnautica.SteamAppId}.acf"))) { return(Path.Combine(appsPath, "common", GameInfo.Subnautica.Name)); } string path = SearchAllInstallations(Path.Combine(appsPath, "libraryfolders.vdf"), GameInfo.Subnautica.SteamAppId, GameInfo.Subnautica.Name); if (string.IsNullOrEmpty(path)) { errors?.Add($"It appears you don't have {GameInfo.Subnautica.Name} installed anywhere. The game files are needed to run the server."); } else { return(path); } return(null); }
public async Task WaitsForRegistryKeyToExist() { const string pathToKey = @"SOFTWARE\Nitrox\test"; RegistryEx.Write(pathToKey, 0); var readTask = Task.Run(async() => { try { await RegistryEx.CompareAsync <int>(pathToKey, v => v == 1337, TimeSpan.FromSeconds(5)); return(true); } catch (TaskCanceledException) { return(false); } }); RegistryEx.Write(pathToKey, 1337); Assert.IsTrue(await readTask); // Cleanup (we can keep "Nitrox" key intact). RegistryEx.Delete(pathToKey); Assert.IsNull(RegistryEx.Read <string>(pathToKey)); }
public static Dictionary <string, Guid> GetPathAndGuids(string shellExPath, bool isDragDrop = false) { Dictionary <string, Guid> dic = new Dictionary <string, Guid>(); string[] parts = isDragDrop ? DdhParts : CmhParts; foreach (string part in parts) { using (RegistryKey cmKey = RegistryEx.GetRegistryKey($@"{shellExPath}\{part}")) { if (cmKey == null) { continue; } foreach (string keyName in cmKey.GetSubKeyNames()) { try { using (RegistryKey key = cmKey.OpenSubKey(keyName)) { if (!GuidEx.TryParse(key.GetValue("")?.ToString(), out Guid guid)) { GuidEx.TryParse(keyName, out guid); } if (!guid.Equals(Guid.Empty)) { dic.Add(key.Name, guid); } } } catch { continue; } } } } return(dic); }
private void AddNewItem() { using (var shellKey = RegistryEx.GetRegistryKey(ShellPath, true, true)) { string keyName = "Item"; NewItemRegPath = ObjectPath.GetNewPathWithIndex($@"{ShellPath}\{keyName}", ObjectPath.PathType.Registry, 0); keyName = RegistryEx.GetKeyName(NewItemRegPath); using (var key = shellKey.CreateSubKey(keyName, true)) { key.SetValue("MUIVerb", ItemText); if (rdoMulti.Checked) { key.SetValue("SubCommands", ""); } else { if (!ItemCommand.IsNullOrWhiteSpace()) { string command; if (!chkSE.Checked) { command = ItemCommand; } else { command = ShellExecuteDialog.GetCommand(ItemFilePath, Arguments, chkSE.Verb, chkSE.WindowStyle); } key.CreateSubKey("command", true).SetValue("", command); } } } } }
public RegExportMenuItem(ITsiRegExportItem item) : base(AppString.Menu.ExportRegistry) { this.Click += (sender, e) => { using (SaveFileDialog dlg = new SaveFileDialog()) { string date = DateTime.Today.ToString("yyyy-MM-dd"); string time = DateTime.Now.ToString("HH.mm.ss"); string filePath = $@"{AppConfig.BackupDir}\{date}\{item.Text} - {time}.reg"; string dirPath = Path.GetDirectoryName(filePath); string fileName = Path.GetFileName(filePath); Directory.CreateDirectory(dirPath); dlg.FileName = fileName; dlg.InitialDirectory = dirPath; dlg.Filter = $"{AppString.Dialog.RegistryFile}|*.reg"; if (dlg.ShowDialog() == DialogResult.OK) { RegistryEx.Export(item.RegPath, dlg.FileName); } if (Directory.GetFiles(dirPath).Length == 0 && Directory.GetDirectories(dirPath).Length == 0) { Directory.Delete(dirPath); } } }; }
public static Dictionary <string, Guid> GetPathAndGuids(string shellExPath) { Dictionary <string, Guid> dic = new Dictionary <string, Guid>(); foreach (string cmhPart in CmhParts) { using (RegistryKey cmKey = RegistryEx.GetRegistryKey($@"{shellExPath}\{cmhPart}")) { if (cmKey == null) { continue; } foreach (string keyName in cmKey.GetSubKeyNames()) { using (RegistryKey key = cmKey.OpenSubKey(keyName)) { if (!GuidInfo.TryGetGuid(key.GetValue("")?.ToString(), out Guid guid)) { GuidInfo.TryGetGuid(keyName, out guid); } if (!guid.Equals(Guid.Empty)) { dic.Add(key.Name, guid); } } } } } return(dic); }
public async Task <ProcessEx> StartPlatformAsync() { ProcessEx steam = ProcessEx.GetFirstProcess("steam", p => p.MainModuleDirectory != null && File.Exists(Path.Combine(p.MainModuleDirectory, "steamclient.dll"))); if (steam != null) { return(steam); } // Steam is not running, start it. string exe = GetExeFile(); if (exe == null) { return(null); } steam = new ProcessEx(Process.Start(new ProcessStartInfo { WorkingDirectory = Path.GetDirectoryName(exe) ?? Directory.GetCurrentDirectory(), FileName = exe, WindowStyle = ProcessWindowStyle.Minimized, Arguments = "-silent" // Don't show Steam window })); // Wait for Steam to get ready. await RegistryEx.CompareAsync <int>(@"SOFTWARE\Valve\Steam\ActiveProcess\pid", v => v == steam.Id, TimeSpan.FromSeconds(45)); return(steam); }
/// <param name="parentPath">子菜单的父菜单的注册表路径</param> public ShellSubMenuForm(string parentPath) { this.ShowInTaskbar = false; this.StartPosition = FormStartPosition.CenterParent; this.MinimumSize = this.Size = new Size(646, 389).DpiZoom(); LstSubItems = new MyListBox { Dock = DockStyle.Fill, Parent = this }; string value = GetValue(parentPath, "SubCommands", null)?.ToString(); if (string.IsNullOrWhiteSpace(value)) { using (var shellKey = RegistryEx.GetRegistryKey($@"{parentPath}\shell")) { if (shellKey != null && shellKey.GetSubKeyNames().Length > 0) { new MultiItemsList(LstSubItems).LoadItems(parentPath); return; } else { using (SubMenuModeForm frm = new SubMenuModeForm()) { frm.ShowDialog(); if (frm.SubMenuMode == 1) { new MultiItemsList(LstSubItems).LoadItems(parentPath); return; } } } } } new CommonMultiItemsList(LstSubItems).LoadItems(parentPath); }
/// <param name="parentPath">子菜单的父菜单的注册表路径</param> public void LoadItems(string parentPath) { this.ParentPath = parentPath; string value = GetValue(ParentPath, "SubCommands", null)?.ToString(); Array.ForEach(value.Split(';'), cmd => SubKeyNames.Add(cmd.TrimStart())); SubKeyNames.RemoveAll(string.IsNullOrEmpty); using (var shellKey = RegistryEx.GetRegistryKey(ShellItem.CommandStorePath, false, true)) { foreach (string keyName in SubKeyNames) { using (var key = shellKey.OpenSubKey(keyName)) { MyListItem item; if (key != null) { item = new SubShellItem(this, keyName); } else if (keyName == "|") { item = new SeparatorItem(this); } else { item = new InvalidItem(this, keyName); } this.AddItem(item); } } } }
private void AddFromParentMenu() { if (!SubShellTypeItem.CanAddMore(this)) { return; } using (ShellStoreDialog dlg = new ShellStoreDialog { ShellPath = this.ParentShellPath, IgnoredKeyNames = new List <string> { this.ParentKeyName } }) { if (dlg.ShowDialog() != DialogResult.OK) { return; } dlg.SelectedKeyNames.ForEach(keyName => { if (!SubShellTypeItem.CanAddMore(this)) { return; } string srcPath = $@"{dlg.ShellPath}\{keyName}"; string dstPath = ObjectPath.GetNewPathWithIndex($@"{ShellPath}\{keyName}", ObjectPath.PathType.Registry); RegistryEx.CopyTo(srcPath, dstPath); this.AddItem(new SubShellItem(this, dstPath)); }); } }
public void LoadItems(string parentPath) { this.ParentPath = parentPath; string sckValue = GetValue(parentPath, "ExtendedSubCommandsKey", null)?.ToString(); if (!sckValue.IsNullOrWhiteSpace()) { this.ShellPath = $@"HKEY_CLASSES_ROOT\{sckValue}\shell"; } else { this.ShellPath = $@"{parentPath}\shell"; } using (var shellKey = RegistryEx.GetRegistryKey(ShellPath)) { if (shellKey == null) { return; } RegTrustedInstaller.TakeRegTreeOwnerShip(shellKey.Name); Array.ForEach(shellKey.GetSubKeyNames(), keyName => { string regPath = $@"{ShellPath}\{keyName}"; int value = Convert.ToInt32(GetValue(regPath, "CommandFlags", 0)); if (value % 16 >= 8) { this.AddItem(new SeparatorItem(this, regPath)); } else { this.AddItem(new SubShellItem(this, regPath)); } }); } }
public void MoveItem(MyListItem item, bool isUp) { int index = this.GetItemIndex(item); MyListItem otherItem = null; if (isUp) { if (index > 1) { otherItem = (MyListItem)this.Controls[index - 1]; this.SetItemIndex(item, index - 1); } } else { if (index < this.Controls.Count - 1) { otherItem = (MyListItem)this.Controls[index + 1]; this.SetItemIndex(item, index + 1); } } if (otherItem != null) { string path1 = GetItemRegPath(item); string path2 = GetItemRegPath(otherItem); string tempPath = ObjectPath.GetNewPathWithIndex(path1, ObjectPath.PathType.Registry); RegistryEx.MoveTo(path1, tempPath); RegistryEx.MoveTo(path2, path1); RegistryEx.MoveTo(tempPath, path2); SetItemRegPath(item, path2); SetItemRegPath(otherItem, path1); } }
private void AddFromParentMenu() { if (!SubShellTypeItem.CanAddMore(this)) { return; } using (ShellStoreDialog dlg = new ShellStoreDialog()) { dlg.IsReference = false; dlg.ShellPath = this.ParentShellPath; dlg.Filter = new Func <string, bool>(itemName => !itemName.Equals(this.ParentKeyName, StringComparison.OrdinalIgnoreCase)); if (dlg.ShowDialog() != DialogResult.OK) { return; } foreach (string keyName in dlg.SelectedKeyNames) { if (!SubShellTypeItem.CanAddMore(this)) { return; } string srcPath = $@"{dlg.ShellPath}\{keyName}"; string dstPath = ObjectPath.GetNewPathWithIndex($@"{ShellPath}\{keyName}", ObjectPath.PathType.Registry); RegistryEx.CopyTo(srcPath, dstPath); this.AddItem(new SubShellItem(this, dstPath)); } } }
protected override void InitializeComponents() { base.InitializeComponents(); this.Text = AppString.Dialog.NewOpenWithItem; btnBrowse.Click += (sender, e) => BrowseFile(); btnOk.Click += (sender, e) => { if (string.IsNullOrEmpty(ItemText)) { MessageBoxEx.Show(AppString.MessageBox.TextCannotBeEmpty); return; } if (string.IsNullOrWhiteSpace(ItemCommand)) { MessageBoxEx.Show(AppString.MessageBox.TextCannotBeEmpty); return; } FilePath = ObjectPath.ExtractFilePath(ItemCommand); AppRegPath = $@"HKEY_CLASSES_ROOT\Applications\{Path.GetFileName(FilePath)}"; if (FilePath == null || RegistryEx.GetRegistryKey(AppRegPath) != null) { MessageBoxEx.Show(AppString.MessageBox.UnsupportedFilename); return; } AddNewItem(); this.DialogResult = DialogResult.OK; }; }
public void LoadItems(string parentPath) { this.ParentPath = parentPath; using (var shellKey = RegistryEx.GetRegistryKey(ShellPath)) { if (shellKey == null) { return; } RegTrustedInstaller.TakeRegTreeOwnerShip(shellKey.Name); Array.ForEach(shellKey.GetSubKeyNames(), keyName => { string regPath = $@"{ShellPath}\{keyName}"; int value = Convert.ToInt32(GetValue(regPath, "CommandFlags", 0)); if (value % 16 >= 8) { this.AddItem(new SeparatorItem(this, regPath)); } else { this.AddItem(new SubShellItem(this, regPath)); } }); } }
public RegLocationMenuItem(ITsiRegPathItem item) : base(AppString.Menu.RegistryLocation) { this.Click += (sender, e) => ExternalProgram.JumpRegEdit(item.RegPath, item.ValueName, AppConfig.OpenMoreRegedit); item.ContextMenuStrip.Opening += (sender, e) => { using (var key = RegistryEx.GetRegistryKey(item.RegPath)) this.Visible = key != null; }; }
public RegLocationMenuItem(ITsiRegPathItem item) : base(AppString.Menu.RegistryLocation) { this.Click += (sender, e) => ShowPath(item.RegPath, PathType.Registry); item.ContextMenuStrip.Opening += (sender, e) => { using (var key = RegistryEx.GetRegistryKey(item.RegPath)) this.Visible = key != null; }; }
public void DeleteMe() { Array.ForEach(BlockedPaths, path => { RegistryEx.DeleteValue(path, this.Value); }); if (!this.Guid.Equals(Guid.Empty)) { ExplorerRestarter.NeedRestart = true; } this.Dispose(); }
public void DeleteMe() { Array.ForEach(GuidBlockedList.BlockedPaths, path => RegistryEx.DeleteValue(path, this.Value)); if (!this.Guid.Equals(Guid.Empty)) { ExplorerRestarter.Show(); } this.Dispose(); }
///<summary>“其他规则”-“公共引用”</summary> private void LoadStoreItems() { using (var shellKey = RegistryEx.GetRegistryKey(ShellItem.CommandStorePath)) { Array.ForEach(Array.FindAll(shellKey.GetSubKeyNames(), itemName => !ShellItem.SysStoreItemNames.Contains(itemName, StringComparer.OrdinalIgnoreCase)), itemName => this.AddItem(new StoreShellItem($@"{ShellItem.CommandStorePath}\{itemName}", true, false))); } }
public static string GetFilePath(Guid guid) { string filePath = null; if (guid.Equals(Guid.Empty)) { return(filePath); } if (FilePathDic.ContainsKey(guid)) { filePath = FilePathDic[guid]; } else { foreach (string clsidPath in ClsidPaths) { using (RegistryKey guidKey = RegistryEx.GetRegistryKey($@"{clsidPath}\{guid:B}")) { if (guidKey == null) { continue; } foreach (string keyName in new[] { "InprocServer32", "LocalServer32" }) { using (RegistryKey key = guidKey.OpenSubKey(keyName)) { if (key == null) { continue; } string value1 = key.GetValue("CodeBase")?.ToString()?.Replace("file:///", "")?.Replace('/', '\\'); if (File.Exists(value1)) { filePath = value1; break; } string value2 = key.GetValue("")?.ToString(); value2 = ObjectPath.ExtractFilePath(value2); if (File.Exists(value2)) { filePath = value2; break; } } } if (File.Exists(filePath)) { break; } } } FilePathDic.Add(guid, filePath); } return(filePath); }
private void AddNewItem() { using (var key = RegistryEx.GetRegistryKey(AppRegPath, true, true)) { key.SetValue("FriendlyAppName", ItemText); } using (var cmdKey = RegistryEx.GetRegistryKey(CommandPath, true, true)) { cmdKey.SetValue("", ItemCommand); RegPath = cmdKey.Name; } }
private void LoadItems() { using (var shellKey = RegistryEx.GetRegistryKey(ShellPath)) { Array.ForEach(Array.FindAll(shellKey.GetSubKeyNames(), itemName => !IgnoredKeyNames.Contains(itemName, StringComparer.OrdinalIgnoreCase)), itemName => { string regPath = $@"{ShellPath}\{itemName}"; list.AddItem(new StoreShellItem(regPath, IsPublic)); }); } }
private void AddNewItem() { using (var key = RegistryEx.GetRegistryKey(AppRegPath, true, true)) { key.SetValue("FriendlyAppName", ItemText); using (var cmdKey = key.CreateSubKey(@"shell\open\command", true)) { cmdKey.SetValue("", ItemCommand); RegPath = cmdKey.Name; } } }
public override void DeleteMe() { RegistryEx.DeleteKeyTree(this.RegPath); int index = this.Parent.Controls.GetChildIndex(this); if (index == this.Parent.Controls.Count - 1) { index--; } this.Parent.Controls[index].Focus(); this.Parent.Controls.Remove(this); this.Dispose(); }
private void LoadItems() { using (var shellKey = RegistryEx.GetRegistryKey(ShellItem.CommandStorePath)) { Array.ForEach(Array.FindAll(shellKey.GetSubKeyNames(), itemName => !SystemItemNames.Contains(itemName, StringComparer.OrdinalIgnoreCase)), itemName => { string regPath = $@"{ShellItem.CommandStorePath}\{itemName}"; list.AddItem(new StoreShellItem(regPath)); RegTrustedInstaller.TakeRegTreeOwnerShip(regPath); }); } }
private bool CheckRegistryKeyForExecutable (UIntPtr key, string subkey, string valueName, RegistryEx.Wow64 wow64, string subdir, string exe) { string key_name = string.Format (@"{0}\{1}\{2}", key == RegistryEx.CurrentUser ? "HKCU" : "HKLM", subkey, valueName); var path = RegistryEx.GetValueString (key, subkey, valueName, wow64); if (string.IsNullOrEmpty (path)) path = null; if (path == null) { return false; } if (!File.Exists (Path.Combine (path, subdir, exe))) { return false; } return true; }