Executing another program from C#, do I need to parse the “command line” from registry myself?

后端 未结 4 1385
悲&欢浪女
悲&欢浪女 2020-12-17 05:29

From the registry, for a given file type, I get a string containing something like this:

\"C:\\Program Files\\AppName\\Executable.exe\" /arg1 /arg2 /arg3
         


        
4条回答
  •  不知归路
    2020-12-17 05:44

    I had a similar problem (parsing a ClickOnce UninstallString from the registry to execute using System.Diagnostics.Process). I resolved it by removing tokens from the end of the uninstall string until I could detect a valid file path.

        public static string GetExecutable(string command)
        {
            string executable = string.Empty;
            string[] tokens = command.Split(' ');
    
            for (int i = tokens.Length; i >= 0; i--)
            {
                executable = string.Join(" ", tokens, 0, i);
                if (File.Exists(executable))
                    break;
            }
            return executable;
        }
    

提交回复
热议问题