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); } } } } }
private static void WriteCommandValue(XmlNode cmdXE, string regPath) { XmlElement fnXE = (XmlElement)cmdXE.SelectSingleNode("FileName"); XmlElement argXE = (XmlElement)cmdXE.SelectSingleNode("Arguments"); XmlElement seXE = (XmlElement)cmdXE.SelectSingleNode("ShellExecute"); string command; string fileName = fnXE?.InnerText.Trim(); string arguments = argXE?.InnerText.Trim(); if (string.IsNullOrEmpty(fileName)) { fileName = CreateCommandFile(fnXE); } if (string.IsNullOrEmpty(arguments)) { arguments = CreateCommandFile(argXE); } fileName = Environment.ExpandEnvironmentVariables(fileName); arguments = Environment.ExpandEnvironmentVariables(arguments); string prefix = argXE?.GetAttribute("Prefix"); //参数前缀 string suffix = argXE?.GetAttribute("Suffix"); //参数后缀 arguments = prefix + arguments + suffix; if (seXE != null) { string verb = seXE.HasAttribute("Verb") ? seXE.GetAttribute("Verb") : "open"; int windowStyle = seXE.HasAttribute("WindowStyle") ? Convert.ToInt32(seXE.GetAttribute("WindowStyle")) : 1; string directory = Environment.ExpandEnvironmentVariables(seXE.GetAttribute("Directory")); command = ShellExecuteDialog.GetCommand(fileName, arguments, verb, windowStyle, directory); } else { command = fileName; if (arguments != string.Empty) { command += $" {arguments}"; } } Registry.SetValue(regPath, "", command); }
protected override void OnClick(EventArgs e) { if (this.Checked) { this.Checked = false; ttpInfo.RemoveAll(); } else { using (ShellExecuteDialog dlg = new ShellExecuteDialog()) { if (dlg.ShowDialog() != DialogResult.OK) { return; } this.Verb = dlg.Verb; this.WindowStyle = dlg.WindowStyle; this.Checked = true; ttpInfo.SetToolTip(this, $"Verb: \"{Verb}\"\nWindowStyle: {WindowStyle}"); } } }