Win32Exception 参数不正确
使用 Process.Start()
运行 exe 文件,但它抛出“Win32Exception 参数不正确”。
Process p = new Process();
Process.Start("C:\Program Files\APS2PP\keyl2000.exe");
我可以通过命令提示符成功运行该文件。
exe file using Process.Start()
but it throws the "Win32Exception the parameter is incorrect".
Process p = new Process();
Process.Start("C:\Program Files\APS2PP\keyl2000.exe");
I can run this file through command prompt successfully.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用双反斜杠或在字符串前面放置 @。
Use double backslashes or put a @ in front of the string.
来自: http://msdn.microsoft.com/en-us/library/53ezey2s .aspx
Win32Exception - 发生错误打开关联文件时。
1) 如果您要使用
Process.Start(String)
的静态方法,则实际上不需要声明Process
对象。2)异常基本上是说由于某种原因无法打开该文件。你确定路径正确吗?您是否尝试过手动打开该文件?
3) 确保在更有条理的地方定义文件路径。例如设置文件。这也有助于消除转义字符的需要。但是,如果您坚持将该字符串保留为内联,至少可以通过在其前面添加 @ 符号来消除对转义字符的需要 (
@"C:\Program Files\SomeFile.exe"
)From: http://msdn.microsoft.com/en-us/library/53ezey2s.aspx
Win32Exception - An error occurred when opening the associated file.
1) If you're going to use the static method of
Process.Start(String)
you don't really need to declare aProcess
object.2) The exception is basically saying that it can not open that file for some reason. 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. 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"
)有关例外的详细信息吗?
根据: http://msdn.microsoft.com/en- us/library/system.componentmodel.win32exception.aspx 此异常有一个内部异常代码,因此您可以通过 google 搜索并查看到底发生了什么。
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.
当我尝试将参数放在与可执行文件名称相同的字符串中时,我遇到了同样的错误,即相当于:
我没有意识到它们需要在单独的字符串中提供。
I had the same error when I tried putting arguments in the same string as the executable name, i.e. the equivalent of:
I didn't realise they need to be supplied in separate strings.