简体   繁体   English

Win32Exception 参数不正确

[英]Win32Exception the parameter is incorrect

exe file using Process.Start() but it throws the "Win32Exception the parameter is incorrect". exe 文件使用Process.Start()但它抛出“Win32Exception 参数不正确”。

Process p = new Process();
Process.Start("C:\Program Files\APS2PP\keyl2000.exe");

I can run this file through command prompt successfully.我可以通过命令提示符成功运行此文件。

Process.Start("C:\Program Files\APS2PP\keyl2000.exe")

使用双反斜杠或在字符串前面放一个@。

 Process.Start(@"C:\Program Files\APS2PP\keyl2000.exe");

From: http://msdn.microsoft.com/en-us/library/53ezey2s.aspx来自:http: //msdn.microsoft.com/en-us/library/53ezey2s.aspx

Win32Exception - An error occurred when opening the associated file. Win32Exception - 打开关联文件时发生错误。

1) If you're going to use the static method of Process.Start(String) you don't really need to declare a Process object. 1)如果您要使用Process.Start(String)的静态方法,您实际上不需要声明Process对象。

//Use...
Process p = new Process();
p.StartInfo = new ProcessStartInfo(filename);
p.Start();

//Or...

Process.Start(filename);

2) The exception is basically saying that it can not open that file for some reason. 2)异常基本上是说由于某种原因它无法打开该文件。 Are you sure the path is correct?你确定路径正确吗? Have you tried opening that file manually?您是否尝试过手动打开该文件?

3) Make sure to define your file paths somewhere more organized. 3)确保在更有条理的地方定义你的文件路径。 Such as a settings file.比如设置文件。 This also helps eliminate the need for escaping the characters.这也有助于消除转义字符的需要。 But, if you insist on leaving that string inline, at least remove the need for escape characters by preceding it with the @ symbol ( @"C:\Program Files\SomeFile.exe" )但是,如果您坚持将该字符串内联,则至少通过在其前面加上 @ 符号( @"C:\Program Files\SomeFile.exe" )来消除对转义字符的需求

Any details on the Exception?有关异常的任何详细信息?

According to: http://msdn.microsoft.com/en-us/library/system.componentmodel.win32exception.aspx this exception has an internal exception code so you can google it and see exactly what happened.根据:http: //msdn.microsoft.com/en-us/library/system.componentmodel.win32exception.aspx这个异常有一个内部异常代码,所以你可以谷歌它,看看到底发生了什么。

I had the same error when I tried putting arguments in the same string as the executable name, ie the equivalent of:当我尝试将参数放在与可执行文件名称相同的字符串中时,我遇到了同样的错误,即相当于:

Process p = new Process();
Process.Start("C:\Program Files\APS2PP\keyl2000.exe /t keyfile.dat");

I didn't realise they need to be supplied in separate strings.我没有意识到它们需要以单独的字符串提供。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM