Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Windows下通过调用启动进程?_C#_Windows - Fatal编程技术网

C# 如何在Windows下通过调用启动进程?

C# 如何在Windows下通过调用启动进程?,c#,windows,C#,Windows,我有以下在Linux下工作的代码: ProcessStartInfo startInfo = new ProcessStartInfo(); // Set in the process the executable and arguments startInfo.FileName = "ps"; startInfo.Arguments = "a"; Process proc = Process.Start(startInfo); proc.WaitForExit(); return p

我有以下在Linux下工作的代码:

ProcessStartInfo startInfo = new ProcessStartInfo(); 

// Set in the process the executable and arguments
startInfo.FileName = "ps";
startInfo.Arguments = "a";

Process proc = Process.Start(startInfo);

proc.WaitForExit();

return proc.ExitCode;
但是,当我尝试在Windows下使用该过程执行简单命令时:

ProcessStartInfo startInfo = new ProcessStartInfo(); 

// Set in the process the executable and arguments
startInfo.FileName = "call";
startInfo.Arguments = "gpedit.msc";

Process proc = Process.Start(startInfo);

proc.WaitForExit();

return proc.ExitCode;
它不工作(我知道在cmd.exe中运行thins命令可以正常工作)

我得到:
win32异常未处理

我还重新阅读了本教程:

我在Linux下经常使用process,但我看不出在Windows中有什么错误。

两个选项:

使用
GPEDIT
参数调用MMC可执行文件

startInfo.FileName = "MMC.EXE";
startInfo.Arguments = "GPEDIT.MSC";
或者在没有参数的情况下调用
GPEDIT.MSC

startInfo.FileName = "GPEDIT.MSC";

CALL
是一个批处理命令,仅可从命令行(poke)获得


我改用start,它工作正常。

调用与代码的可执行文件在同一目录中吗?
call
是一个批处理命令,只能从命令行获得。您应该能够将
gpedit.msc
指定为“文件名”没有指定任何参数来启动管理工具。gpedit.msc是您尝试运行的进程-因此应该是文件名您是否读取了异常?1-)调用确实在同一目录中2-)我将尝试不进行调用并报告它是否工作