[英]System.ComponentModel.Win32Exception when starting process - file not found, but file exists
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.
它应该读取一个XML文件,然后以自定义的延迟启动我的程序。 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. 5秒钟后,这将运行指定的进程(
C:\\Program Files\\...\\RtkNGUI64.exe -s
)。
Now, three of the programs won't start, giving me a System.ComponentModel.Win32Exception
: "Das System kann die angegebene Datei nicht finden." 现在,其中三个程序将无法启动,给我一个
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. 但是XML解析正确,并且我要启动的文件位于XML文件中指定的位置。
The problem concerns only these three files: 该问题仅涉及以下三个文件:
Intel HotkeysCmd - C:\\Windows\\System32\\hkcmd.exe 英特尔HotkeysCmd-C:\\ Windows \\ System32 \\ hkcmd.exe
Intel GFX Tray - C:\\Windows\\System32\\igfxtray.exe 英特尔GFX托盘-C:\\ Windows \\ System32 \\ igfxtray.exe
Intel Persistance - C:\\Windows\\System32\\igfxpers.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%
) 我认为问题出在文件的位置:它们都位于C:\\ Windows \\ System32中,所有其他正常运行的程序都位于外部(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? 我是否必须授予程序某种访问权限才能在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. 显然,您使用的是Windows的64位版本。 The c:\\windows\\system32 and c:\\program files directories are subject to a feature called "file system redirection".
c:\\ windows \\ system32和c:\\ program文件目录具有称为“文件系统重定向”的功能。 It is an appcompat feature, it helps to ensure that 32-bit processes don't try to use 64-bit executables.
这是一个appcompatpat功能,它有助于确保32位进程不要尝试使用64位可执行文件。 They'll get redirected to c:\\windows\\syswow64 and c:\\program files (x86).
它们将被重定向到c:\\ windows \\ syswow64和c:\\ program文件(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. 因此,当您尝试在c:\\ program files \\ realtek \\ etcetera中启动文件时,您的32位程序将被重定向到c:\\ program files(x86)\\ realtek \\ etcetera。 A directory that doesn't exist, kaboom.
一个不存在的目录,kaboom。 Same ingredient for igfxtray.exe
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. 您需要更改程序的平台目标,以便它可以作为本机64位进程运行,并避免了现在遇到的重定向问题。 Project + Properties, Build tab, change the "Platform target" setting to AnyCPU.
在“项目+属性”的“构建”选项卡上,将“平台目标”设置更改为AnyCPU。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.