这是我面临的一个愚蠢而棘手的问题.
以下代码运行良好(它启动计算器):
ProcessStartInfo psStartInfo = new ProcessStartInfo();
psStartInfo.FileName = @"c:\windows\system32\calc.exe";
Process ps = Process.Start(psStartInfo);
Run Code Online (Sandbox Code Playgroud)
但是SoundRecorder的下面一个不起作用.它给了我"系统找不到指定的文件"错误.
ProcessStartInfo psStartInfo = new ProcessStartInfo();
psStartInfo.FileName = @"c:\windows\system32\soundrecorder.exe";
Process ps = Process.Start(psStartInfo);
Run Code Online (Sandbox Code Playgroud)
我可以使用开始 - >运行 - >"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");
}
Run Code Online (Sandbox Code Playgroud)
dxi*_*xiv 13
很可能您的应用程序是32位,并且在64位Windows引用中C:\Windows\System32可以透明地重定向到C:\Windows\SysWOW6432位应用程序.calc.exe碰巧存在于两个地方,而只soundrecorder.exe存在于真实的地方System32.
从Start / Run父进程启动时是64位,explorer.exe因此没有重定向,并且C:\Windows\System32\soundrecorder.exe找到并启动了64位.
从文件系统重定向器:
在大多数情况下,只要32位应用程序尝试访问%windir%\ System32,就会将访问权限重定向到%windir%\ SysWOW64.
[编辑] 从同一页面:
32位应用程序可以通过%windir%\ Sysnative替换%windir%\ System32来访问本机系统目录.
所以下面的工作soundrecorder.exe将从(真实的)开始C:\Windows\System32.
psStartInfo.FileName = @"C:\Windows\Sysnative\soundrecorder.exe";
Run Code Online (Sandbox Code Playgroud)
旧线程,但提供了另一种可能的情况
就我而言,我在Process.Start中使用了参数
System.Diagnostics.Process.Start("C:\\MyAppFolder\\MyApp.exe -silent");
Run Code Online (Sandbox Code Playgroud)
我把它改成
ProcessStartInfo info = new ProcessStartInfo("C:\\MyAppFolder\\MyApp.exe");
info.Arguments = "-silent";
Process.Start(info)
Run Code Online (Sandbox Code Playgroud)
然后它起作用了。
| 归档时间: |
|
| 查看次数: |
12069 次 |
| 最近记录: |