这是我面临的一个愚蠢而棘手的问题。
下面的代码运行良好(它启动了Calculator):
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和Windows 7 OS中使用C#。
更新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
可以透明地重定向到C:\Windows\SysWOW64
32位应用。calc.exe
恰好在两个地方都soundrecorder.exe
存在,而System32
仅在真实中存在。
当您从Start / Run
父进程启动时是64位的,explorer.exe
因此不执行任何重定向,并且C:\Windows\System32\soundrecorder.exe
找到并启动了64位。
从文件系统重定向器:
在大多数情况下,每当32位应用程序尝试访问%windir%\ System32时,访问都会重定向到%windir%\ SysWOW64。
[编辑]在同一页面上:
通过将%windir%\ Sysnative替换为%windir%\ System32,32位应用程序可以访问本机系统目录。
所以下面的工作soundrecorder.exe
将从(real)开始C:\Windows\System32
。
psStartInfo.FileName = @"C:\Windows\Sysnative\soundrecorder.exe";
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句