启动进程时出现System.ComponentModel.Win32Exception - 找不到文件,但文件存在

pas*_*ein 8 c# exception file-not-found win32exception file-access

我正在尝试为自动启动创建一个经理.它应该读取一个XML文件,然后以自定义延迟启动我的程序.例如:

<startup id="0">
    <name>Realtek Audio Manager</name>
    <process arguments="-s">C:\Program Files\Realtek\Audio\HDA\RtkNGUI64.exe</process>
    <delay>5</delay>
</startup>
Run Code Online (Sandbox Code Playgroud)

这将C:\Program Files\...\RtkNGUI64.exe -s在5秒后运行指定的进程().

现在,有三个程序无法启动,给我一个System.ComponentModel.Win32Exception:"Das System kann die angegebene Datei nicht finden." ("系统无法找到指定的文件.")

但是XML被正确解析,我想要启动的文件位于我在XML文件中指定的位置.

该问题仅涉及这三个文件:
Intel HotkeysCmd - C:\ Windows\System32\hkcmd.exe
Intel GFX Tray - C:\ Windows\System32\igfxtray.exe
Intel Persistance - C:\ Windows\System32\igfxpers.exe

我认为问题来自文件的位置:它们都位于C:\ Windows\System32中,而所有其他工作程序都位于外部(C:\ Program Files,C:\ Program Files(x86) ,D:\ Program Files,%AppData%)

我是否必须为我的程序提供某种访问权限才能在C:\ Windows\System32中启动程序?我该怎么办?

如果没有,那么我在这些程序中出错的原因是什么?

编辑 - 我的代码:

delegate(object o)
{
    var s = (Startup) o;
    var p = new System.Diagnostics.Process
                {
                    StartInfo =
                        new System.Diagnostics.ProcessStartInfo(s.Process, s.Arguments)
                };
    try
    {
        s.Process = @"C:\Windows\System32\igfxtray.exe"; // For debugging purposes
        System.Diagnostics.Process.Start(s.Process);
        icon.ShowBalloonTip(2000, "StartupManager",
                            "\"" + s.Name + "\" has been started.",
                            System.Windows.Forms.ToolTipIcon.Info);
    }
    catch (System.ComponentModel.Win32Exception)
    {
        icon.ShowBalloonTip(2000, "StartupManager",
                            "\"" + s.Name + "\" could not be found.",
                            System.Windows.Forms.ToolTipIcon.Error);
    }
}
Run Code Online (Sandbox Code Playgroud)

Han*_*ant 19

显然,您使用的是64位版本的Windows.c:\ windows\system32和c:\ program files目录受一个名为"文件系统重定向"的功能的约束.它是一个appcompat功能,它有助于确保32位进程不会尝试使用64位可执行文件.它们将被重定向到c:\ windows\syswow64和c:\ program files(x86).

因此,当您尝试在c:\ program files\realtek\etcetera中启动文件时,您的32位程序将被重定向到c:\ program files(x86)\ realtek\etcetera.一个不存在的目录,kaboom.igfxtray.exe的成分相同

您需要更改程序的平台目标,以便它可以作为本机64位进程运行,并避免您现在拥有的重定向问题.Project + Properties,Build选项卡,将"Platform target"设置更改为AnyCPU.