Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"File not found" error launching system32\winsat.exe using Process.Start()

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();

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.

I tried several ways to call winsat.exe:

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

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

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

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

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

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

Thanks,

Rex

like image 778
Rex Hsu Avatar asked May 30 '13 02:05

Rex Hsu


People also ask

Where is WinSAT Exe located in Windows 10?

Winsat.exe is located in the C:\Windows\System32 folder. The file size on Windows 10/8/7/XP is 3,367,424 bytes. Winsat.exe is a Windows core system file. It is a Microsoft signed file. The program has no visible window.

Why can't I launch windows-on Windows 64-bit version of Windows WinSAT?

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.

What is Windows system assessment tool (WinSAT) Exe?

The process known as Windows System Assessment Tool or Windows Sistem Deðerlendirme Aracý belongs to software Microsoft Windows Operating System or Microsoft Windows Ýþletim Sistemi by Microsoft (www.microsoft.com). Description: The original winsat.exe is an important part of Windows and rarely causes problems.

How do I fix Windows 10 error code winsat formal?

Usually, the error is a onetime thing and isn’t a serious error. Press Windows key once. Type cmd in the Start Search. Right click the Command Prompt from the search results and select run as administrator. Type winsat formal and press Enter.


1 Answers

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();

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

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");
like image 108
Simon MᶜKenzie Avatar answered Oct 12 '22 23:10

Simon MᶜKenzie