Pass shortcut arguments in .bat (batch)

2

0

In a .exe shortcut, I can use extra arguments. But how to pass those arguments in a .bat file?

selfmade.exe

Posted 2014-09-20T21:01:36.837

Reputation: 78

1Some more details? What exactly you mean by pass arguments in a bat file? – Kamil – 2014-09-20T21:15:01.433

In a shortcut you can add a parameter, for example, a custom resolution. I want to use this parameter in a .bat file, because a .bat file uses only .exe(s) and not shortcuts. – selfmade.exe – 2014-09-20T21:23:41.563

Ah, I see. You just want to replace shortcut with command line script. – Kamil – 2014-09-20T21:25:07.120

Yeap, exactly this! – selfmade.exe – 2014-09-20T21:26:11.293

Answers

5

To pass argument to bat or cmd file - you just run script with parameters, like this:

script.cmd parameter1 parameter2

Inside script - if you pass arguments - you will have %1 %2 %3 special variables available, and you can use them like this

echo First argument is %1
echo Second argument is %2

echo Starting application with arguments
application.exe %1 %2

More information:

Windows batch scripting / Command line arguments at Wikibooks

EDIT / added later after discussion in comments.

To replace shortcut with command line file (cmd or bat) - create .bat or .cmd file like this:

"C:\Some Location\Some application.exe" argument1 argument2

Kamil

Posted 2014-09-20T21:01:36.837

Reputation: 2 524

the .bat goes like this:

first.exe second.exe

and I want to add "-vidmode 1440,900,60" (without quotes).

I tried it but it doesnt work. I dont know if the scpaces are the cause. In the shotcut it would be

"C:\folder\1.exe" -vidmode 1440,900,60 – selfmade.exe – 2014-09-20T21:36:34.530

Is there a way to grab ALL the args passed, so they can ALL be passed to i.e. application.exe (in python the syntax would be *args in the function arg list)? – nmz787 – 2016-07-06T21:23:35.583

3

In exactly the same way:

BatchFile.bat param1 param2 ...

Inside the batch file the parameters are addressed as %1, %2, ...

AFH

Posted 2014-09-20T21:01:36.837

Reputation: 15 470