System.ComponentModel.Win32Exception起动过程时 - 未找到文件,但文件存在 [英] System.ComponentModel.Win32Exception when starting process - file not found, but file exists

查看:1422
本文介绍了System.ComponentModel.Win32Exception起动过程时 - 未找到文件,但文件存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建我的自动启动的经理。它应显示为一个XML文件,然后用自定义的延迟开始我的计划。例如:

 <启动ID =0> 
<名称>的Realtek音频管理器< /名称>
<方法的参数= - 的> C:\Program Files\Realtek\Audio\HDA\RtkNGUI64.exe< /法>
<延迟> 5℃/延迟>
< /启动>

这将运行指定的程序( C:\Program Files\。 ..\RtkNGUI64.exe -S )5秒。



现在,三个程序都将无法启动,给我一个 System.ComponentModel.Win32Exception :DAS系统卡恩死angegebene Datei nicht芬登。 (系统无法找到指定的文件。)



但XML被正确解析,我要开始该文件是在我指定的位置在XML文件



这个问题只涉及这三个文件:结果
英特尔HotkeysCmd - C:\Windows\System32\hkcmd。 EXE结果
英特尔GFX托盘 - C:\Windows\System32\igfxtray.exe结果
英特尔持久性 - C:\Windows\System32\igfxpers.exe



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



我必须给我的程序某种访问权限在C启动程序:\Windows\System32?我会怎么做呢?



如果不是,这可能是我得到这些程序错误的原因是什么?



编辑 - 我的代码:

 委托(对象o)
{
变种S =(启动) O;
变种P =新的System.Diagnostics.Process
{
的StartInfo =
新System.Diagnostics.ProcessStartInfo(s.Process,s.Arguments)
};

{
s.Process = @C:\Windows\System32\igfxtray.exe //为了进行调试
System.Diagnostics.Process.Start(s.Process);
icon.ShowBalloonTip(2000年,StartupManager,
\+ s.Name +\已启动,
System.Windows.Forms.ToolTipIcon。信息);
}
赶上(System.ComponentModel.Win32Exception)
{
icon.ShowBalloonTip(2000年,StartupManager,
\+ s.Name + \​​找不到,
System.Windows.Forms.ToolTipIcon.Error)。
}
}


解决方案

显然,您使用的是Windows的64位版本。在C:\windows\system32和c:\program文件的目录都受到了所谓的文件系统重定向功能。它是一个应用程序兼容性功能,它有助于确保32位进程不要尝试使用64位可执行文件。他们将获得的重定向的到c:\windows\syswow64和c:\program文件(x86)



所以,当你尝试启动在C文件:\program files\realtek\etcetera,您的32位程序将被重定向到c:\program文件(x86)的\realtek\etcetera。一个不存在的目录,KABOOM。对于igfxtray.exe相同成分



您将需要改变你的程序的目标平台,因此它可以作为一个原生的64位进程中运行,避免了重定向问题,你现在有。项目+属性,构建选项卡,将目标平台设置为值为anycpu。


I am trying to create a manager for my autostarts. It should read an XML file and then start my programs with a custom delay. For example:

<startup id="0">
    <name>Realtek Audio Manager</name>
    <process arguments="-s">C:\Program Files\Realtek\Audio\HDA\RtkNGUI64.exe</process>
    <delay>5</delay>
</startup>

This runs the specified process (C:\Program Files\...\RtkNGUI64.exe -s) after 5 seconds.

Now, three of the programs won't start, giving me a System.ComponentModel.Win32Exception: "Das System kann die angegebene Datei nicht finden." ("The system was not able to find the specified file.")

But the XML is parsed correctly, and the file I want to start is at the location I specified in the XML file.

The problem concerns only these three files:
Intel HotkeysCmd - C:\Windows\System32\hkcmd.exe
Intel GFX Tray - C:\Windows\System32\igfxtray.exe
Intel Persistance - C:\Windows\System32\igfxpers.exe

I think that the problem comes from the location of the files: they all are located in C:\Windows\System32, and all the other, working programs are located outside (C:\Program Files, C:\Program Files (x86), D:\Program Files, %AppData%)

Do I have to give my program some kind of access rights to start programs in C:\Windows\System32? How would I do that?

If not, what could be the reason I get errors with these programs?

EDIT - my code:

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

解决方案

Clearly you are using a 64-bit version of Windows. The c:\windows\system32 and c:\program files directories are subject to a feature called "file system redirection". It is an appcompat feature, it helps to ensure that 32-bit processes don't try to use 64-bit executables. They'll get redirected to c:\windows\syswow64 and c:\program files (x86).

So when you try to start a file in c:\program files\realtek\etcetera, your 32-bit program will be redirected to c:\program files (x86)\realtek\etcetera. A directory that doesn't exist, kaboom. Same ingredient for igfxtray.exe

You'll need to change your program's platform target so it can run as a native 64-bit process and avoid the redirection problem you now have. Project + Properties, Build tab, change the "Platform target" setting to AnyCPU.

这篇关于System.ComponentModel.Win32Exception起动过程时 - 未找到文件,但文件存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆