"找不到文件"错误启动system32\winsat.exe使用的Process.Start() [英] "File not found" error launching system32\winsat.exe using Process.Start()

查看:638
本文介绍了"找不到文件"错误启动system32\winsat.exe使用的Process.Start()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试运行 Windows系统评估工具( winsat.exe)使用以下代码:

I'm trying to run the Windows System Assessment Tool (winsat.exe) using the following code:

System.Diagnostics.Process WinSPro =
    new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo WinSSInfo = 
    new System.Diagnostics.ProcessStartInfo();
WinSSInfo.FileName = "cmd.exe";
WinSSInfo.Arguments = "/k winsat.exe";
WinSPro.StartInfo = WinSSInfo;
WinSPro.Start();

如果我只调用cmd.exe,即使我调用regedit.exe,作品。
但是,当我尝试调用winsat.exe作为cmd.exe的参数时,它失败。
命令提示符显示:

This code works if I only call cmd.exe, and even if I call regedit.exe it still works. However, when I try to call winsat.exe as a argument of cmd.exe, it fails. The command prompt shows this:


'winsat.exe' is not recognized as an internal or external command, 
operable program or batch file.

我尝试过几种方法调用winsat.exe:

I tried several ways to call winsat.exe:


  1. 通过将winsat.exe分配给 ProcessStartInfo.FileName 直接调用它。它失败,并且 Win32Exception 系统找不到指定的文件

  1. Call it directly by assigning "winsat.exe" to ProcessStartInfo.FileName. It fails with a Win32Exception: The system cannot find the file specified

如上所述,使用完整路径 - @c:\windows \system32\winsat.exe

As above, using the full path - @"c:\windows\system32\winsat.exe". It fails with the same error.

以系统管理员身份运行代码。

Run the code as the System Administrator. It still fails.

在编码示例中调用winsat.exe。

Call winsat.exe as in the coded example. It failed as I explained earlier.



有趣的是,从代码中启动的命令提示符只能看到.dll文件在c:\windows \system32。

It's interesting that the command prompt launched from the code can only see .dll files in c:\windows\system32.

有人有任何想法为什么winsat.exe无法通过启动System.Diagnostics.Process

Does anyone have any idea why winsat.exe cannot be launched through System.Diagnostics.Process? Are there any limitations which I've misunderstood?

感谢,

Rex

推荐答案

使用 com / en-us / library / aa384187%28v = vs.85%29.aspx> Windows-on Windows 64位重定向。发生了什么事情,你的启动请求(从32位进程)被重定向到%windir%\SysWOW64\winsat.exe 。由于64位安装上没有此特定可执行文件的32位版本,因此启动失败。要绕过此过程并允许32位进程访问本机(64位)路径,可以引用%windir%\sysnative

winsat.exe is redirected using Windows-on Windows 64-bit redirection. What's happening is that your launch request (from a 32-bit process) is being redirected to %windir%\SysWOW64\winsat.exe. Since there's no 32-bit version of this particular executable on 64-bit installs, the launch fails. To bypass this process and allow your 32-bit process to access the native (64-bit) path, you can reference %windir%\sysnative instead:

Process WinSPro = new Process();
ProcessStartInfo WinSSInfo = new ProcessStartInfo();
WinSSInfo.FileName = @"c:\windows\sysnative\winsat.exe";
WinSPro.StartInfo = WinSSInfo;
WinSPro.Start();

或者,如果将程序构建为x64,则可以将路径保留为 c:\windows \system32

Alternatively, if you build your program as x64, you can leave the path as c:\windows\system32.

请注意,最好使用 Environment.GetFolderPath 获取Windows目录的路径,以防操作系统安装在非标准位置:

Note that it's best to use Environment.GetFolderPath to get the path to the windows directory, just in case the OS is installed in a non-standard location:

WinSSInfo.FileName = Path.Combine(
    Environment.GetFolderPath(Environment.SpecialFolder.Windows),
    @"sysnative\winsat.exe");

这篇关于"找不到文件"错误启动system32\winsat.exe使用的Process.Start()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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