CMD: Make sure that only one parameter has been passed

Software Software
Software Software used Ask the Experts™
when a batch-file is executed in cmd. I want to make sure that exactly one parameter has been passed.
How can I do this?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Bill PrewTest your restores, not your backups...
Top Expert 2016

Just check %2 and make sure it is blank, like:

if "%~2" NEQ "" (
    echo Too many parms entered.
    exit /b

Open in new window

Fabrice LambertConsulting
Distinguished Expert 2017

batch script parameters are named %1, %2, %3 ect (up to %9).
So, Just check if %2 hold any value.

But why don't you ignore additional parameters if you arn't interrested in them ?
It is simplier than an akward checking.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial