C#中的Process.Start系统找不到指定的文件错误 [英] Process.Start in C# The system cannot find the file specified error

查看:1046
本文介绍了C#中的Process.Start系统找不到指定的文件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This is a silly and tricky issue that I am facing.

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

The below code works well (it launches Calculator):

ProcessStartInfo psStartInfo = new ProcessStartInfo();
psStartInfo.FileName = @"c:\windows\system32\calc.exe";

Process ps = Process.Start(psStartInfo);

但是下面的SoundRecorder无效。它给我系统找不到指定的文件错误。

However the below one for SoundRecorder does not work. It gives me "The system cannot find the file specified" error.

ProcessStartInfo psStartInfo = new ProcessStartInfo();
psStartInfo.FileName = @"c:\windows\system32\soundrecorder.exe";

Process ps = Process.Start(psStartInfo);

我可以通过使用Start-> Run-> c:\windows \system32\soundrecorder.exe命令。

I am able to launch Sound Recorder by using Start -> Run -> "c:\windows\system32\soundrecorder.exe" command.

任何想法出了什么问题?

Any idea whats going wrong?

我正在使用Visual Studio 2015中并使用Windows 7 OS的C#。

I am using C# in Visual Studio 2015 and using Windows 7 OS.

更新1 :我尝试了 File.Exists 检查,它显示了MessageBox从下面的代码中:

UPDATE 1: I tried a File.Exists check and it shows me MessageBox from the below code:

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 的引用将透明地重定向到 C:\Windows\SysWOW64 (适用于32位应用程序)。 calc.exe 恰好在两个地方都存在,而 soundrecorder.exe 存在于真正的中仅限System32

Most likely your app is 32-bit, and in 64-bit Windows references to C:\Windows\System32 get transparently redirected to C:\Windows\SysWOW64 for 32-bit apps. calc.exe happens to exist in both places, while soundrecorder.exe exists in the true System32 only.

开始/运行启动时,父进程是64位 explorer.exe ,因此无需进行重定向,而64位 C:\Windows\System32\soundrecorder.exe 已找到并启动。

When you launch from Start / Run the parent process is the 64-bit explorer.exe so no redirection is done, and the 64-bit C:\Windows\System32\soundrecorder.exe is found and started.

来自文件系统重定向器


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

In most cases, whenever a 32-bit application attempts to access %windir%\System32, the access is redirected to %windir%\SysWOW64.






在同一页面上:


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

32-bit applications can access the native system directory by substituting %windir%\Sysnative for %windir%\System32.

以下操作可以从(实际) C:\Windows\System32 启动 soundrecorder.exe

So the following would work to start soundrecorder.exe from the (real) C:\Windows\System32.

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

这篇关于C#中的Process.Start系统找不到指定的文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆