public void Invoke() { RegistryKey root = Registry.ClassesRoot; var applications = root.OpenSubKey("Applications", RegistryKeyPermissionCheck.ReadSubTree); var currentApplication = applications.OpenSubKey(Path.GetFileName(this.ApplicationPath), RegistryKeyPermissionCheck.ReadSubTree); Action OnFail = () => { Process.Start(this.ApplicationPath, "\"" + this.Owner.ParsingName + "\""); applications.Close(); root.Close(); }; if (currentApplication == null) { OnFail(); return; } var command = currentApplication.OpenSubKey(@"shell\open\command", RegistryKeyPermissionCheck.ReadSubTree); if (command == null) { command = currentApplication.OpenSubKey(@"shell\edit\command", RegistryKeyPermissionCheck.ReadSubTree); } if (command == null) { OnFail(); return; } var commandValue = command.GetValue("").ToString(); var argsArray = Shell32.CommandLineToArgs(commandValue).ToList(); var executable = argsArray[0]; argsArray.RemoveAt(0); for (int i = 0; i < argsArray.Count; i++) { if (argsArray[i] != "%1" && argsArray[i] != "%L" && argsArray[i].ToLowerInvariant().Contains("photoviewer.dll")) { argsArray[i] = "\"" + argsArray[i].Replace(",", "") + "\","; } else if ((argsArray[i] == "%1" || argsArray[i] == "%L") && !argsArray[i].ToLowerInvariant().Contains("photoviewer.dll")) { argsArray[i] = "\"" + argsArray[i] + "\""; } } var args = String.Join(" ", argsArray).Replace("%1", this.Owner.ParsingName).Replace("%L", this.Owner.ParsingName).Replace(@"\\", @"\"); commandValue = Environment.ExpandEnvironmentVariables(commandValue); Process.Start(executable, args); command.Close(); currentApplication.Close(); applications.Close(); root.Close(); }
private bool ProcessCommand(string commandLine) { var args = Shell32.CommandLineToArgs(commandLine); var commandName = args[0]; var command = AllCommands.FirstOrDefault(c => c.Command.Equals(commandName, StringComparison.InvariantCultureIgnoreCase)); if (command == null) { return(false); } var commandArgs = new string[] { }; if (args.Length > 1) { commandArgs = args.SubArray(1, args.Length - 1); } ExecuteCommand(command, commandArgs); return(true); }