这是我面对的一个愚蠢和棘手的问题。C#中的Process.Start系统找不到指定的文件错误
下面的代码工作得很好(它会启动计算器):
ProcessStartInfo psStartInfo = new ProcessStartInfo();
psStartInfo.FileName = @"c:\windows\system32\calc.exe";
Process ps = Process.Start(psStartInfo);
然而,一个低于SoundRecorder不起作用。它给我“系统找不到指定的文件”错误。
ProcessStartInfo psStartInfo = new ProcessStartInfo();
psStartInfo.FileName = @"c:\windows\system32\soundrecorder.exe";
Process ps = Process.Start(psStartInfo);
我能够使用开始 - >运行 - >“c:\ windows \ system32 \ soundrecorder.exe”命令启动录音机。
任何想法最新怎么回事?
我在Visual Studio 2015中使用C#并使用Windows 7操作系统。
更新1:我尝试了File.Exists
检查,它让我从下面的代码的MessageBox:
if (File.Exists(@"c:\windows\system32\soundrecorder.exe"))
{
ProcessStartInfo psStartInfo = new ProcessStartInfo();
psStartInfo.FileName = @"c:\windows\system32\soundrecorder.exe";
Process ps = Process.Start(psStartInfo);
}
else
{
MessageBox.Show("File not found");
}
为了安全起见,请正确使用路径。 ' “C:\ WINDOWS \ SYSTEM32 \ soundrecorder.exe”'。你有没有确定在浏览器中查看该文件存在? 'System.IO'中的'File.Exists()'是什么意思? –
这两个代码适合我。 –
你可以做一个'if(File.Exists(@“c:\ windows \ system32 \ soundrecorder.exe”)'以确保该文件在尝试启动该进程之前已存在。 – Nkosi