[英]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: 不确定这些是否是您问题的原因,但是从问题中发布的示例中,请注意以下几点:
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.