简体   繁体   中英

Process.Start for system32 applications - The System Cannot Find the File Specified

I have written a simple custom shell application for Windows 8.1 systems in WPF. It functions fine, but I need to start some of the applications in the Run section of the registry. Fine and good, however, no matter what I try, they don't launch, and I receive an error: "The system cannot find the file specified."

This is designed for 64 bit systems, so I've heard that using C:\\Windows\\Sysnative\\ for the path rather than C:\\Windows\\System32\\ is a fix, but it didn't work. My code is as follows:

Process processToStart = new Process 
{ 
    StartInfo = 
    { 
        FileName = @"C:\Windows\Sysnative\hkcmd.exe", 
        WorkingDirectory = @"C:\Windows\Sysnative\") 
    }
};
processToStart.Start();

The way I found to get this to work was to disable WOW64 file system redirection. Nothing else seemed to work.
From this link: http://tcamilli.blogspot.co.uk/2005/07/disabling-wow64-file-system.html

[DllImport("Kernel32.Dll", EntryPoint="Wow64EnableWow64FsRedirection")]
public static extern bool EnableWow64FSRedirection(bool enable);

Wow64Interop.EnableWow64FSRedirection(false)
Process processToStart = new Process 
{ 
    StartInfo = 
    { 
        FileName = @"C:\Windows\Sysnative\hkcmd.exe", 
        WorkingDirectory = @"C:\Windows\Sysnative\") 
    }
};
processToStart.Start();
Wow64Interop.EnableWow64FSRedirection(true)

Not sure if these might be the cause of your issue but from your example posted in the question, note these few points:

  1. StartInfo.FileName should only contain the fileName, not the path.
  2. If you're trying to execute hkcmd.exe, you wrote it as hkcmnd.exe (extra N).

In the example above I believe it effectively looks like specifying the filename and workingdirectory repeatedly causes a file to not be found. See this link I used to check and this link as well

Sysnative was not present on my machine (Win 7 x64), it might be in Windows 8.

I couldn't get hkcmd.exe to execute, it threw an error you had as well, however, executing cmd.exe and notepad.exe is fine.

Sample code:

System.Diagnostics.Process processToStart = new System.Diagnostics.Process();
processToStart.StartInfo.FileName = "cmd.exe"; //or notepad.exe
processToStart.StartInfo.WorkingDirectory = @"C:\Windows\System32\";
processToStart.Start();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM