windows 如何使用另一个 .exe 包装对 .exe(带参数)的调用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/166493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:23:03  来源:igfitidea点击:

How can I wrap a call to an .exe (with arguments) with another .exe?

windowsbatch-fileexecutable

提问by Liam

I have a Windows executable (say program.exe) and I want to provide users with 2 launchers that will pass different arguments to it.

我有一个 Windows 可执行文件(比如program.exe),我想为用户提供 2 个将向其传递不同参数的启动器。

program.exe -a
program.exe -b

I can easily do this with 2 batch files, but I would rather provide users with 2 .exe files as they are more likely to be used correctly without editing.

我可以使用 2 个批处理文件轻松完成此操作,但我更愿意为用户提供 2 个 .exe 文件,因为它们更有可能在不进行编辑的情况下被正确使用。

Is there an easy way to create such an executable?

有没有一种简单的方法来创建这样的可执行文件?

回答by Matthew Dresser

Why create new executables? Why not just create desktop shortcuts to launch the single exe.

为什么要创建新的可执行文件?为什么不创建桌面快捷方式来启动单个 exe。

回答by dguaraglia

You might try this: http://www.abyssmedia.com/quickbfc/

你可以试试这个:http: //www.abyssmedia.com/quickbfc/

If you want something really, really small, you'd probably need to make your own Pascal/C program. I suggest Pascal because there is a very nice free compilerthat produces really small .EXEs without the need to used a tweaked library (that would be the onlyC shortcoming in this case).

如果你想要一些非常非常小的东西,你可能需要制作自己的 Pascal/C 程序。我建议使用 Pascal,因为有一个非常好的免费编译器,它可以生成非常小的 .EXE,而无需使用经过调整的库(这将是这种情况下唯一的C 缺点)。

Cheers.

干杯。

回答by RomanM

Not sure if its exactly what your trying to do but check thisfor possible solutions.

不知道它到底是什么你想要做的,但检查可能的解决方案。

That answers the question in the title, as for what you write here, why dont you just parse the arguments and depending on them have the two functionalities inside one executable ?

这回答了标题中的问题,至于您在这里写的内容,为什么不解析参数并根据它们在一个可执行文件中具有两个功能?

回答by plinth

If you have the source code to your application, you can change its behavior based on the name of the executable. It's not hard - in main, look at argv[0] and change the options based on that.

如果您拥有应用程序的源代码,则可以根据可执行文件的名称更改其行为。这并不难 - 在主要内容中,查看 argv[0] 并基于此更改选项。

回答by stevechol

If you are using .Net you can read the information presented as parameters from another application or batch file. It's part of the Framework. Here it is is VB.NET

如果您使用的是 .Net,您可以从另一个应用程序或批处理文件中读取作为参数显示的信息。它是框架的一部分。这是VB.NET

For Each Arg As String In Environment.GetCommandLineArgs() //Process the arguments Next Arg

For Each Arg As String In Environment.GetCommandLineArgs() //处理参数 Next Arg