简体   繁体   English

system32应用程序的Process.Start - 系统无法找到指定的文件

[英]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. 我在WPF中为Windows 8.1系统编写了一个简单的自定义shell应用程序。 It functions fine, but I need to start some of the applications in the Run section of the registry. 它运行正常,但我需要在注册表的Run部分启动一些应用程序。 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. 这是为64位系统设计的,所以我听说使用C:\\ Windows \\ Sysnative \\作为路径而不是C:\\ Windows \\ System32 \\是一个修复,但它不起作用。 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. 我发现让它工作的方法是禁用WOW64文件系统重定向。 Nothing else seemed to work. 似乎没有其他工作。
From this link: http://tcamilli.blogspot.co.uk/2005/07/disabling-wow64-file-system.html 从这个链接: 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. StartInfo.FileName应该只包含fileName,而不是路径。
  2. If you're trying to execute hkcmd.exe, you wrote it as hkcmnd.exe (extra N). 如果您尝试执行hkcmd.exe,则将其写为hkcmnd.exe(额外N)。

In the example above I believe it effectively looks like specifying the filename and workingdirectory repeatedly causes a file to not be found. 在上面的例子中,我认为它实际上看起来像指定文件名和workdirectory重复导致找不到文件。 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. 我的机器上没有Sysnative(Win 7 x64),它可能在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. 我无法让hkcmd.exe执行,它也引发了一个错误,但是,执行cmd.exe和notepad.exe没问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C# ProcessStartInfo 和 Process.Start 在 System32 中找不到程序 - C# ProcessStartInfo and Process.Start cannot find programs in System32 Process.Start()中的错误 - 系统找不到指定的文件 - Error in Process.Start() – The System cannot find the file specified Process.Start(…)引发“系统找不到指定的文件” - Process.Start(…) throws “The system cannot find the file specified” “系统找不到指定的文件”错误on process.Start(); - “The system cannot find the file specified” error on process.Start(); Process.Start() 中的错误——系统找不到指定的文件 - Error in Process.Start() -- The system cannot find the file specified Windows \\ System32文件夹中的Process.Start - Process.Start in Windows\System32 folder 使用Process.Start()启动system32 \\ winsat.exe时出现“找不到文件”错误 - “File not found” error launching system32\winsat.exe using Process.Start() Process.Start():系统找不到指定的文件,但我的文件路径似乎是合法的 - Process.Start(): The system cannot find the file specified, but my file path seems to be legit Process.Start in C# The system cannot find the file specified error - Process.Start in C# The system cannot find the file specified error Process.Start("IIS Manager.lnk") 失败并显示“系统找不到指定的文件” - Process.Start("IIS Manager.lnk") fails with "The system cannot find the file specified"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM