![](/img/trans.png)
[英]C# ProcessStartInfo and Process.Start cannot find programs in System32
[英]Process.Start for system32 applications - The System Cannot Find the File Specified
我在WPF中為Windows 8.1系統編寫了一個簡單的自定義shell應用程序。 它運行正常,但我需要在注冊表的Run部分啟動一些應用程序。 然而,無論我嘗試什么,他們都不會啟動,並且我收到錯誤:“系統無法找到指定的文件”。
這是為64位系統設計的,所以我聽說使用C:\\ Windows \\ Sysnative \\作為路徑而不是C:\\ Windows \\ System32 \\是一個修復,但它不起作用。 我的代碼如下:
Process processToStart = new Process
{
StartInfo =
{
FileName = @"C:\Windows\Sysnative\hkcmd.exe",
WorkingDirectory = @"C:\Windows\Sysnative\")
}
};
processToStart.Start();
我發現讓它工作的方法是禁用WOW64文件系統重定向。 似乎沒有其他工作。
從這個鏈接: 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)
不確定這些是否是您問題的原因,但是從問題中發布的示例中,請注意以下幾點:
在上面的例子中,我認為它實際上看起來像指定文件名和workdirectory重復導致找不到文件。 看到我以前檢查過的 鏈接以及此鏈接
我的機器上沒有Sysnative(Win 7 x64),它可能在Windows 8中。
我無法讓hkcmd.exe執行,它也引發了一個錯誤,但是,執行cmd.exe和notepad.exe沒問題。
示例代碼:
System.Diagnostics.Process processToStart = new System.Diagnostics.Process();
processToStart.StartInfo.FileName = "cmd.exe"; //or notepad.exe
processToStart.StartInfo.WorkingDirectory = @"C:\Windows\System32\";
processToStart.Start();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.