C#Process.Start()BAT文件的对话框

时间:2022-08-29 14:45:32

I have a C# program that needs to spawn a .BAT command file during its execution. No problem. I can just use (for example)...

我有一个C#程序,需要在执行期间生成.BAT命令文件。没问题。我可以使用(例如)......

System.Diagnostics.Process.Start("PublishFeed.bat", "file.xml");

...in order to run the cmd with a parameter. In the debugger, this works fine. However, when I run the executable in production, Windows pops up a dialog box that says "Do you want to open this file? Name: PublishFeed.bat Type: Unknown File Type.

...为了使用参数运行cmd。在调试器中,这很好。但是,当我在生产中运行可执行文件时,Windows会弹出一个对话框,显示“是否要打开此文件?名称:PublishFeed.bat类型:未知文件类型。

If I click OK, it runs fine.

如果我单击确定,它运行正常。

Why is this dialog appearing? Seems especially odd for it to claim Unknown File Type, when clicking OK seems to run the BAT file with no problem.

为什么会出现此对话框?声称未知文件类型似乎特别奇怪,单击确定似乎运行BAT文件没有问题。

thanks all!

P.S. Yes, I can probably remove the need for the BAT file, but I would still like to understand the issue.

附:是的,我可以删除对BAT文件的需求,但我仍然想了解这个问题。

1 个解决方案

#1


I think the most reliable way to do this is to just speficy to open that batch with cmd:

我认为最可靠的方法是使用cmd打开该批次:

System.Diagnostics.Process.Start("cmd", "/c PublishFeed.bat file.xml");

#1


I think the most reliable way to do this is to just speficy to open that batch with cmd:

我认为最可靠的方法是使用cmd打开该批次:

System.Diagnostics.Process.Start("cmd", "/c PublishFeed.bat file.xml");