Win32Exception 参数不正确

发布于 2024-10-16 05:06:46 字数 211 浏览 9 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

深爱成瘾 2024-10-23 05:06:46
Process.Start("C:\Program Files\APS2PP\keyl2000.exe")

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

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

Use double backslashes or put a @ in front of the string.

 Process.Start(@"C:\Program Files\APS2PP\keyl2000.exe");
诗笺 2024-10-23 05:06:46

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

Win32Exception - 发生错误打开关联文件时。

1) 如果您要使用 Process.Start(String) 的静态方法,则实际上不需要声明 Process 对象。

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

//Or...

Process.Start(filename);

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 a Process object.

//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. 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")

野生奥特曼 2024-10-23 05:06:46

有关例外的详细信息吗?

根据: 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.

岁月静好 2024-10-23 05:06:46

当我尝试将参数放在与可执行文件名称相同的字符串中时,我遇到了同样的错误,即相当于:

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

我没有意识到它们需要在单独的字符串中提供。

I had the same error when I tried putting arguments in the same string as the executable name, i.e. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文