1

我在 WPF 中为 Windows 8.1 系统编写了一个简单的自定义 shell 应用程序。它运行良好,但我需要在注册表的“运行”部分启动一些应用程序。很好,但是,无论我尝试什么,它们都无法启动,并且我收到错误消息:“系统找不到指定的文件。”

这是为 64 位系统设计的,所以我听说使用 C:\Windows\Sysnative\ 作为路径而不是 C:\Windows\System32\ 是一种修复方法,但它不起作用。我的代码如下:

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

2 回答 2

4

我发现让它工作的方法是禁用 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)
于 2015-04-01T15:39:26.043 回答
0

不确定这些是否可能是您的问题的原因,但从您在问题中发布的示例中,请注意以下几点:

  1. StartInfo.FileName 应该只包含文件名,而不是路径。
  2. 如果您尝试执行 hkcmd.exe,则将其编写为 hkcmnd.exe(额外 N)。

在上面的示例中,我相信它实际上看起来像是重复指定文件名和工作目录导致找不到文件。请参阅我曾经检查过的此链接以及此链接

我的机器(Win 7 x64)上不存在 Sysnative,它可能在 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();
于 2015-03-19T16:41:37.327 回答