Process.Start in C#系统找不到指定文件的错误

这是我面临的一个愚蠢而棘手的问题。

以下代码运行良好(它启动计算器):

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"); } 

您的应用程序很可能是32位,而在64位Windows中,对C:\Windows\System32引用会透明地重定向到32位应用程序的C:\Windows\SysWOW64calc.exe碰巧存在于两个地方,而soundrecorder.exe仅存在于真正的System32

从“ Start / RunStart / Run ,父进程是64位explorer.exe因此不会进行重定向,并且会找到并启动64位C:\Windows\System32\soundrecorder.exe

从文件系统重定向器 :

在大多数情况下,只要32位应用程序尝试访问%windir%\ System32,就会将访问权限重定向到%windir%\ SysWOW64。


[编辑]从同一页面:

32位应用程序可以通过将%windir%\ Sysnative替换为%windir%\ System32来访问本机系统目录。

因此,以下将从(真正的) C:\Windows\System32启动soundrecorder.exe

 psStartInfo.FileName = @"C:\Windows\Sysnative\soundrecorder.exe";