When starting a batch file, then one can also specify input parameters. The parameters can be accessed by the batch file like environment variables, and have the values %1 to %9.Format a:
To check if a parameter is given:
More Info MS KB71247IF "%1"!="" ECHO Got %1
Note there also exists the input parameter %0, which is actually the batch-filename it self.
Note one can also use the SHIFT command incase the input parameter doesn't have to be in a certain order. SHIFT moves the parameter one to the left so %1 disappears, %2 becomes %1, %3 becomes %2 and etc. This behavior can be useful when having a batch file which receives an undefined order or amount of parameters.
:PARSELOOP
IF "%1"=="" GOTO ENDPARSE
IF "%1"=="DEBUG" SET BUILD=DEBUG
IF "%1"=="RELEASE" SET BUILD=RELEASE
SHIFT
GOTO PARSELOOP
:ENDPARSE
I have a list.txt file of filenames,which I want to use 1 at a time as parameters in a batch file.
I thought I could use
I am trying to help a friend out.
He has a batch chatroom that echo's a line of text to another batch file to ban users..
echo if %computername% == %BanUser% taskkill /im cmd.exe>>BannedUser.bat
The problem is the code above just sends the name of my computer.
how can I actually port the variable %computername% to BannedUser.bat?
set testvar=computername
echo if %%testvar%%==%BanUser% taskkill /im cmd.exe>>BannedUser.bat