【问题标题】:Process.Start for system32 applications - The System Cannot Find the File SpecifiedSystem32 应用程序的 Process.Start - 系统找不到指定的文件
【发布时间】:2015-03-19 16:03:38
【问题描述】:

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

【问题讨论】:

    标签: c# .net process windows-8.1 system32


    【解决方案1】:

    我发现让它工作的方法是禁用 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)
    

    【讨论】:

    • 请注意,当有嵌套调用时,'Wow64EnableWow64FsRedirection' 方法可能无法正常工作,因此您应该改用'Wow64DisableWow64FsRedirection'。刚刚写了一篇关于如何使用 C# 从 System32 目录运行任何应用程序的文章:ourcodeworld.com/articles/read/909/…
    【解决方案2】:

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

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

    在上面的示例中,我相信它实际上看起来像是重复指定文件名和工作目录会导致找不到文件。 See this link I used to checkthis link as well

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

    【讨论】:

    • 是的,刚刚删除了多余的 n。那是一个错误,对此感到抱歉。我刚刚尝试了 Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\hkcmd.exe"),它适用于 C:\Windows\system32\hkcmd.exe,但是当我在路径上执行 file.exists 时,即使该文件存在于该目录中,它也会出现负面影响。超级奇怪。
    • @Giallo 不用担心。 :D 你能试试这里指定的修复吗? :stackoverflow.com/questions/29149512/… 这也适用于 hkcmd 以外的其他程序: System.IO.Directory.SetCurrentDirectory(@"C:\Windows\System32\"); System.Diagnostics.Process.Start("cmd.exe");
    • 我刚刚尝试了您的确切代码,将 cmd.exe 替换为 hkcmd.exe,但仍然出现异常。不过,cmd.exe 确实有效。特别是hkcmd.exe,由于某种原因无法启动。
    • 我的怀疑(我无法在我的设置上进行测试以确认)是这个问题类似于我在评论中附加的 SO 链接。不过我不确定。 (编辑:刚刚意识到我很愚蠢并粘贴了错误的链接)这个:stackoverflow.com/questions/13974653/…
    • 这超出了我的能力,因为我无法从这里进行太多测试,祝你好运!似乎是权限问题。另一种方法是找到一种方法来启动一个管理员隐藏的 cmd.exe,它会调用并运行 hkcmd。我已经设法通过管理员 cmd 手动启动 hkcmd 进程(显示在任务管理器上)。
    猜你喜欢
    • 2019-05-14
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多