相关疑难解决方法(0)

从C#执行另一个程序,我是否需要自己解析注册表中的"命令行"?

从注册表中,对于给定的文件类型,我得到一个包含以下内容的字符串:

"C:\Program Files\AppName\Executable.exe" /arg1 /arg2 /arg3
Run Code Online (Sandbox Code Playgroud)

或有时:

"C:\Program Files\AppName\Executable.exe" /arg1 /arg2 /arg3 "%1"
Run Code Online (Sandbox Code Playgroud)

为了让我执行这个程序,并传递一个文件名作为参数(我知道它接受),我是否必须自己解析这个字符串,或者是否有一个运行时类为我做这个?请注意,我不是要求处理两者之间是否有"%1"的区别,而是我需要拆分可执行文件的名称,分别获取命令行参数.

我尝试只是附加/注入文件的完整路径和文件的名称传递到上面的字符串并将整个shebang传递给Process.Start,但当然它只需要文件名作为单个参数,所以这不是工作.

基本上,上面必须像这样手动完成:

Process proc = new Process();
proc.StartInfo.FileName = @"C:\Program Files\AppName\Executable.exe";
proc.StartInfo.Arguments = "/arg1 /arg2 /arg3 \"" + fileName + "\"";
proc.Start();
Run Code Online (Sandbox Code Playgroud)

我尝试使用UseShellExecute,但这没有帮助.还有其他指针吗?

要清楚,我想要这个:

String commandPath = ReadFromRegistry();
String fullCommand = commandPath + " " + fileName; // assuming not %1
Process.Start(fullCommand); // <-- magic happens here
Run Code Online (Sandbox Code Playgroud)

c# shellexecute

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

shellexecute ×1