What does this script do (Windows CMD) - windows

SET /P A=SPR
IF /I "%A:~,1%" EQU "d" (
IF EXIST %1 (
IF NOT EXIST %2 (
COPY %1 %2
)
)
)

First, I suggest to open a command prompt window and run the following commands:
set /?
if /?
copy /?
call /? ... explains %1 and %2.
For each command the help is output which you should read from top to bottom.
This small batch file first prompts the batch file user for a string with prompt text SPR. The string entered by the user is assigned to environment variable A if the user enters anything at all as expected by this batch file.
Next a case-insensitive string comparison is done to check if the first character of the string entered by the user is d or D.
It would be much better to use comparison operator == instead of EQU in this case. == always makes a string comparison while EQU first tries to compare integers and if that fails because it is not possible to convert both comparison arguments to signed 32-bit integers, a string comparison is done. The second argument d is not a signed 32-bit integer.
The batch file must be started with two arguments being in this case two file names without or with wildcards. I suppose the batch file expects two file names without or with path without wildcards.
If the first condition is true, the batch file checks next if source file with name passed to batch file as first argument exists and next if target file passed to batch file as second argument does not exist. The source file is copied to target file if those 2 conditions are true.
More fail safe would be:
SET "Input=?"
SET /P "Input=SPR: "
IF /I "%Input:~0,1%" == "d" (
IF "%~1" == "" GOTO :EOF
IF "%~2" == "" GOTO :EOF
IF EXIST "%~1" IF NOT EXIST "%~2" COPY "%~1" "%~2"
)
The environment variable Input is now predefined with ? as string. So when the user just hits RETURN or ENTER without entering anything at all, the environment variable Input is nevertheless defined with ? as string and next command IF works, but of course the condition is in this case false.
The IF condition as is results in an exit of batch execution because of an syntax error only when the first entered character is ". In all other cases the IF condition works now and runs a case-insensitive string comparison.
The improved batch file checks next if the batch file was really started with two argument strings as expected and exit the batch file with a jump to predefined label for End Of File if either first or second argument is an empty string (or a string consisting only of one or two double quotes).

Related

If statement in batch file doesn't execute(Possible syntax issue?)

I am using the below script to help automate some processes that would make my work life easier. When running this current version it faults out and closes the program right as soon as the first if statement executes. Did quite a bit of research on my own and the code looks to be correct. The program closed so fast I couldn't read a reason why. So I ran all the output into a txt file. It looks as if the program faults out for a syntax reason. I unfortunately don't have the file with me and don't have the exact error. I can post it tomorrow when it is in front of me.
::Turns off unnecessary messages from Command Prompt
echo off
::Copies files over from the NAS drive that are required for setup
echo Transfering files from NAS1...
if not exist "%userprofile%\Desktop\Install_Files" mkdir %userprofile%\Desktop\Install_Files
xcopy /Y \\nas1\Volume_1\"Tech Department"\"General Windows POS Preperation"\* "%userprofile%\Desktop\Install_Files"
echo File Transfer Complete
::Start installation of Foxit Reader
echo Installing Foxit Reader...
start /w %userprofile%\Desktop\Install_Files\"FoxitReader831_current version".exe
echo Installations Complete
::Changes background by changing the file pathway in the registry value
echo Setting Background...
REG ADD "HKCU\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d %userprofile%\Desktop\Install_Files\NewTMS1024x768.jpg /f
::Changes the Workgroup and Computer Name
echo Setting Computer Name...
SET /P PCNAME=Please enter computer name:
wmic computersystem where "Name='%computername%'" rename "%PCNAME%"
echo Setting Workgroup...
SET /P WGNAME=Please enter workgroup name:
Wmic computersystem where name="%computername%" call joindomainorworkgroup name="%WGNAME%"
::Selecting which POS Software to install
SET /P POSNAME=Please enter POS Software to install (a:Aldelo m:MAPOS t:TRPOS):
if /i %POSNAME% == "m"
(
::Transfers required files from NAS drive to Install Folder
echo Transferring install files...
xcopy /Y \\nas1\Volume_1\"Tech Department"\"POS Software"\MAPOS\* "%userprofile%\Desktop\Install_Files"
::Installs MAPOS and Groovv SDK for card processing
echo Installing GroovvSDK...
start /w %userprofile%\Desktop\Install_Files\GroovvSDK_Client_Setup_v3.9.6
echo Installing MAPOS...
start /w %userprofile%\Desktop\Install_Files\mapos_install
)
if /i %POSNAME% == "t"
(
::Transfers required install file for TRPOS
echo Transferring install files...
xcopy /Y \\nas1\Volume_1\"Tech Department"\"POS Software"\TRPOS\TRPOS_install.exe "%userprofile%\Desktop\Install_Files"
::Installs TRPOS
start /w %userprofile%\Desktop\Install_Files\TRPOS_install.exe
)
if /i %POSNAME% == "a"
(
)
else
(
echo No POS Software selected or improper input
)
::Force restarts the computer so changes will take effect
::shutdown.exe /r /t 00
There are two problems with your ifs
The first one is related to how the parser handles the commands. The line
if %POSNAME% == "m"
is not comparing the value inside the variable against a literal string. What is happening is that the parser expands the variable reference (%POSNAME%) replacing the reference with the value inside the command and then tries to execute the resulting command, without any variable reference, only the value. So, for expected values stored in POSNAME variable, the command executed and the result will be
if %POSNAME% == "m"
value parsed as result
--------------------------------------------------------------
POSTNAME is empty -> if == "m" syntax error
POSTNAME is a -> if a == "a" false
POSTNAME is m -> if m == "m" false
In the first case the command fails because there is not any value in the left side of the == operator. The variable is empty and nothing can be placed in the command to be executed.
The second case seems logical, but sometimes the third case is not so obvious. Why false? Because the value in the right side of the == is a quoted literal while the value in the left side is an unquoted literal, so both values do not match.
You can solve this problem simply quoting both sides
if "%POSNAME%"=="m"
value parsed as result
--------------------------------------------------------------
POSTNAME is empty -> if "" == "m" false
POSTNAME is a -> if "a" == "a" false
POSTNAME is m -> if "m" == "m" true
(note: you can also unquote both sides, but it is not recommended unless you are completely sure what the values on both sides are and that the resulting command will not generate problems)
The second problem in your code is parenthesis placement. The batch syntax requires them to be properly placed:
If present, the opening parenthesis in the if clause must be in the same line that contains the if
If there is an else clause then the closing if parenthesis must be in the else line.
If there is an else opening parenthesis, it must be in the else line
So, this
if "%POSNAME%"=="m"
(
.....
)
is not a valid syntax. You can see here samples of how to place the parenthesis.
For starters... there is a problem with the IF statements. You need to quote both sides of the == and remove spaces. Change this format
if /i %POSNAME% == "m"
to this
if /i "%POSNAME%"=="m"
Try that and post results.

Extracting file name from array element in batch

I have an environment variable like this
set BINARY[0]=C:\binary.bin
From which I'm trying to extract the full file name
set "x=0"
:binloop
if defined BINARY[%x%] (
call echo %%BINARY[%x%]%%
FOR %%i IN ("%%BINARY[%x%]%%") DO (
set FNAME=%%~nxi
)
set /a "x+=1"
GOTO binloop
)
rem ...
However for some reason, it tries to do:
set FNAME=%BINARY[0]%
instead of
set FNAME=binary.bin
What's wrong with the code and why?
Open a command prompt window, run set /? and read the output help pages explaining when and how to use delayed expansion in a code block for the commands IF and FOR.
%% in a batch file is interpreted as literal percent character which is the reason why a loop variable in a command executed directly in a command prompt window must be specified with just one percent sign while the same loop in a batch file requires two percent signs on referencing the loop variable.
When the Windows command processor encounters an opening parenthesis which marks the beginning of a command block, it searches for the matching closing parenthesis and replaces all environment variables references with syntax %VariableName% by the current value of the variable or nothing in case of variable does not exist. Then after the entire command block was parsed the IF or FOR is executed and used is once or more times the already preprocessed command block.
You could use
#echo off
setlocal EnableExtensions EnableDelayedExpansion
set "BINARY[1]=C:\binary1.bin"
set "BINARY[0]=C:\binary0.bin"
set "x=0"
:binloop
if defined BINARY[%x%] (
call echo %%BINARY[%x%]%%
for %%i in ("!BINARY[%x%]!") do (
set FNAME=%%~nxi
set FNAME
)
set /a "x+=1"
goto binloop
)
endlocal
which outputs
C:\binary0.bin
FNAME=binary0.bin
C:\binary1.bin
FNAME=binary1.bin
The command line
call echo %%BINARY[%x%]%%
is something special. This line is preprocessed before execution of command IF to
call echo %BINARY[0]%
respectively on second run to
call echo %BINARY[1]%
By usage of command CALL the single command line is processed like a subroutine or another batch file which means the line is preprocessed once more resulting in execution of
echo C:\binary0.bin
and on second run in execution of
echo C:\binary1.bin
which is the reason why the output is as expected here. But there is no double preprocessing for the environment variable reference in FOR.
Much better would be most likely the following code:
#echo off
setlocal EnableExtensions EnableDelayedExpansion
set "BINARY[1]=C:\binary1.bin"
set "BINARY[0]=C:\binary0.bin"
for /F "tokens=1* delims==" %%I in ('set "BINARY[" 2^>nul') do (
set "FNAME=%%~nxJ"
set FNAME
)
endlocal
The command set outputs all variables with their name and equal sign and their values which start with the specified string when there is whether parameter /A or /P used and the parameter does not contain an equal sign in an alphabetically sorted list. So the output of
set "BINARY[" 2>nul
as used in the command FOR is
BINARY[0]=C:\binary0.bin
BINARY[1]=C:\binary1.bin
which is processed by the FOR loop which splits each line into two strings based on first occurrence of the equal sign because of tokens=1* delims==. The first string is the variable name assigned to loop variable I. And the second string is everything after first equal sign assigned to loop variable J being the next character in ASCII table.
2>nul is used to suppress the error message output by command SET to STDERR by redirecting it to device NUL if there is no environment variable defined with a name starting with BINARY[ in any case. The redirection operator > must be escaped with ^ as otherwise command processor would exit batch processing on this line because of 2>nul resulting in a syntax error on FOR command line at this position.
Note: Because of alphabetically sorted output by command SET the environment variable BINARY[10] is output after BINARY[0] and before BINARY[1] and BINARY[2]. So if the order is important, the first batch solution is needed or the environment variables are created with number in square brackets have all same number of digits with leading zeros, i.e. 00000, 00001, ..., 00002, 00010, 00011, ...
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
call /?
echo /?
endlocal /?
for /?
goto /?
if /?
set /?
setlocal /?
And see also Microsoft article about Using command redirection operators.

Trying to conditionally change a file path in a windows batch script

I have a simple script that launches an XML file path in Notepad++
Unfortunately, the generated file path for some of the files is incorrect and I'm trying to compensate for it in the script (ideal fix is clearly to resolve the path issue but at the moment this is not an option).
Here is what I have, apologies for the code I'm very new to Batch Script...
set /p filePath= Enter file path:
if "%filePath%" == "1" goto xmlMenu
else if "%filePath%" == "file://path/of/file/*/*/*/*/A/*.XML"
set filePath="file://path/of/file/*/*/*/*/B/*.XML"
goto openXML
I would like the filePath variable to inherit the rest of the path from the user input but at the moment its explicitly setting the path with the wildcards. There also seems to be a problem with the way I have stated the condition as it appears to set the path to /B/*.XML regardless of the else if condition.
There are many errors, but as you say, youre new.
First, if the filepath you enter is "1" then you should arrive safely at xmlmenu.
The next line will generate an error because with an else clause,
the If-true instruction must be (parenthesised)
the ( must occur on the same physical line as the if
the sequence ) else ( must all be on the same physical line (which need not be the same as the if)
In any case, the else is redundant. If the condition is not true, the jump will not happen, hence the next statement line will be executed.
if...==... is true if the string on the left is identical to the sring on the right, hence you would need for the entered string to be absolutely identical to file://path/of/file/*/*/*/*/A/*.XML for the if to be true. The action-statment also must be on the same physical line as the if, so this is a second source of syntax errors.
the set is then executed, assigning that famous string (in quotes) to the variable filepath. And then we're off to openxml.
Note that \ is a path separator in Windows; / is a switch-specifier.
Now - if you were to explain what you want to do - perhaps enter a filename which may be somewhere in a directory structure and if it's found then assign what? to the variable filepath. One or two examples would be a good idea.
This should get a usable system going. The numeric check is incomplete, but would be adequate. I've not made it bullet-proof against a user determined to break it...
#ECHO OFF
SETLOCAL
:again
SET "filepath="
set /p filePath="Please enter filepath as yyyymmdd : "
IF NOT DEFINED filepath GOTO :EOF
if "%filePath%" == "1" goto xmlMenu
:: test to see whether entered data is numeric
SET /a "filepath=%filepath%" 2>nul
IF %filepath%==0 echo invalid entry - numerics only, please&GOTO again
IF %filepath% lss 19800100 GOTO badymd
IF %filepath% gtr 20991231 GOTO badymd
SET filepath=\path\prefix\%filepath:~0,4%\%filepath:~4,2%\%filepath:~6,2%
:: This is just to show the filepath constructed
ECHO filepath is "%filepath%"
IF NOT exist "%filepath%\A\*.xml" ECHO "%filepath%\A\*.xml" does NOT exist&GOTO again
IF NOT exist "%filepath%\B\*.xml" ECHO "%filepath%\B\*.xml" does NOT exist&GOTO again
SET "filepath=%filepath%\B\*.xml"
goto openXML
:badymd
ECHO invalid entry - 4 digits FOR year, 2 FOR month an 2 FOR day, please
GOTO again
:xmlmenu
ECHO AT xmlmenu&GOTO :eof
:openxml
ECHO AT openxml with filepath="%filepath%"&GOTO :eof
GOTO :EOF
Obviously, change the path prefix to suit.
For an input of 20140220, the path ....\2014\02\20 would be constructed. Then there's a check for and this +\B\*.xml - I can only presume both must exist to proceed to openxml.

Windows: copy a file until the file not exist

I want to use a Windows batch file in to copy a file (myfile0001.bdg) from one specific directory to another. But I want to check if the file in the target directory exists and if the answer is yes, increment the file with 0001 and check again if the file exists (myfile0002.bdg) and so on, until the file does not exist, and copy the file with the new title.
So, if in the target directory, I have these files:
myfile0001.bdg
myfile0002.bdg
myfile0003.bdg
myfile0004.bdg
myfile0005.bdg
myfile0006.bdg
The new file should be named myfile0007.bdg. The next time I will execute the batch, the new file will be myfile0008.bdg, etc.
I know there is a command "IF EXIST" but I don't know to do what I need.
==============
I'm under Windows 7 x32
The source directory is "C:\USERS\RAMBYTES\DOCUMENTS\"
The target directory is "P:\BACKUP\"
The file is "MYFILE0001.BDG"
Something like this:
#echo off
set source_file=C:\USERS\RAMBYTES\DOCUMENTS\MYFILE0001.BDG
set target_dir=P:\BACKUP\
set done=0
for /l %%i in (1,1,1000) do (
call :check_and_copy %%i
if errorlevel 1 goto :eof
)
goto :eof
:check_and_copy
setlocal EnableDelayedExpansion
set num=000000%1
set fnum=!num:~-4!
set fname=%target_dir%\myfile%fnum%.bdg
rem echo %fname%
if not exist "%fname%" (
echo copying %source_file% to %fname%
exit /b 1
)
exit /b 0
There is no error handling in case there are more than a 1000 files present in the target directory. If you want to increas the file limit, you need to adjust the "main" for loop and the "formatting" of the number in the sub-program
The trick with adding the leading zeros was taken from here: https://stackoverflow.com/a/9430912/330315
#ECHO OFF
SET destdir=c:\destdir
SET newname=myfile0000
FOR /f %%i IN (' dir /b /on %destdir%\myfile????.bdg ' ) DO SET newname=%%~ni
SET newname=1%newname:~-4%
SET /a newname+=1
SET newname=myfile%newname:~-4%.bdg
COPY myfile0001.bdg %destdir%\%newname%
change the destination directory as desired, and include the source directory if required.
Take the file name.
Extract the numeric part.
Check if the corresponding target name exists.
If so,
4.1) increase the numeric part;
4.2) if it doesn't exceed the highest possible number go to Step 3;
4.3) otherwise terminate.
If the target name doesn't exist, copy the file with the current numeric part and terminate.
Although algorithmically the condition in 4.2 may be more natural to be checked just after increasing the numeric part, like I put it above, the below script performs the check at a different point, at the beginning of the loop, which starts just after extracting the original numeric value from the source filename. Implementationally, that seemed to me more convenient.
In all other respects, the script implements the same algorithm:
#ECHO OFF
SET "fname=%~n1"
SET counter=1%fname:~-4%
:loop
IF %counter% GTR 19999 (
1>&2 ECHO Cannot copy the file: no free slots.
EXIT /B 1
)
SET "targetname=%~2\%fname:~0,-4%%counter:~1%%~x1"
IF EXIST "%targetname%" (
SET /A counter+=1
GOTO loop
) ELSE (
COPY %1 "%targetname%"
)
To explain some parts:
The tilde (~) in references to positional parameters means de-quoting of the correspondent parameter.
Sometimes in the script, the tilde is also directly followed by a modifier. Two modifiers are used here, n and x. The former causes the parameter to expand to the corresponding file name only (without the path and the extension) and the latter extract only the extension.
You can learn more about modifier in the built-in of the FOR command (by running
The fname environment variable is needed because extracting of name parts can only be done on environment variables. The %fname:~-4 expression, in particular, evaluates to the last four characters of the fname value. More specifically, it reads: extract the substring that starts at the 4th character from the end and, as -4 isn't followed by another argument, includes all the characters from that point till the end of the string.
Another similar-looking expression, %fname:~0,-4%, does the opposite: it returns the contents of fname except the last four characters. The meaning of the numbers is this: extract the substring that starts at the beginning of the string (offset 0) and spans the range up to and including the character at the offset of 4 from the end.
One more expression of this kind, %counter:~1, extracts the characters starting from the second one (i.e. offset 1) and up to the end of string (no second argument).
Run SET /? to find out more about string expressions.
The counter implementation may also require explanation. The 1 added in front of the numeric part of the file name is needed so that the entire value could be interpreted and processed correctly when incrementing it.
The thing is, a numeric value starting with a 0 is treated as an octal by the CMD command processor, so, putting 1 at the beginning makes it to interpret the number as a decimal, which it actually is. When constructing the complete name of the target file, we simply need to discard the added 1, which is what the %counter:~1 is used for.

Using parameters in batch files at Windows command line

In Windows, how do you access arguments passed when a batch file is run?
For example, let's say I have a program named hello.bat. When I enter hello -a at a Windows command line, how do I let my program know that -a was passed in as an argument?
As others have already said, parameters passed through the command line can be accessed in batch files with the notation %1 to %9. There are also two other tokens that you can use:
%0 is the executable (batch file) name as specified in the command line.
%* is all parameters specified in the command line -- this is very useful if you want to forward the parameters to another program.
There are also lots of important techniques to be aware of in addition to simply how to access the parameters.
Checking if a parameter was passed
This is done with constructs like IF "%~1"=="", which is true if and only if no arguments were passed at all. Note the tilde character which causes any surrounding quotes to be removed from the value of %1; without a tilde you will get unexpected results if that value includes double quotes, including the possibility of syntax errors.
Handling more than 9 arguments (or just making life easier)
If you need to access more than 9 arguments you have to use the command SHIFT. This command shifts the values of all arguments one place, so that %0 takes the value of %1, %1 takes the value of %2, etc. %9 takes the value of the tenth argument (if one is present), which was not available through any variable before calling SHIFT (enter command SHIFT /? for more options).
SHIFT is also useful when you want to easily process parameters without requiring that they are presented in a specific order. For example, a script may recognize the flags -a and -b in any order. A good way to parse the command line in such cases is
:parse
IF "%~1"=="" GOTO endparse
IF "%~1"=="-a" REM do something
IF "%~1"=="-b" REM do something else
SHIFT
GOTO parse
:endparse
REM ready for action!
This scheme allows you to parse pretty complex command lines without going insane.
Substitution of batch parameters
For parameters that represent file names the shell provides lots of functionality related to working with files that is not accessible in any other way. This functionality is accessed with constructs that begin with %~.
For example, to get the size of the file passed in as an argument use
ECHO %~z1
To get the path of the directory where the batch file was launched from (very useful!) you can use
ECHO %~dp0
You can view the full range of these capabilities by typing CALL /? in the command prompt.
Using parameters in batch files: %0 and %9
Batch files can refer to the words passed in as parameters with the tokens: %0 to %9.
%0 is the program name as it was called.
%1 is the first command line parameter
%2 is the second command line parameter
and so on till %9.
parameters passed in on the commandline must be alphanumeric characters and delimited by spaces. Since %0 is the program name as it was called, in DOS %0 will be empty for AUTOEXEC.BAT if started at boot time.
Example:
Put the following command in a batch file called mybatch.bat:
#echo off
#echo hello %1 %2
pause
Invoking the batch file like this: mybatch john billy would output:
hello john billy
Get more than 9 parameters for a batch file, use: %*
The Percent Star token %* means "the rest of the parameters". You can use a for loop to grab them, as defined here:
http://www.robvanderwoude.com/parameters.php
Notes about delimiters for batch parameters
Some characters in the command line parameters are ignored by batch files, depending on the DOS version, whether they are "escaped" or not, and often depending on their location in the command line:
commas (",") are replaced by spaces, unless they are part of a string in
double quotes
semicolons (";") are replaced by spaces, unless they are part of a string in
double quotes
"=" characters are sometimes replaced by spaces, not if they are part of a
string in double quotes
the first forward slash ("/") is replaced by a space only if it immediately
follows the command, without a leading space
multiple spaces are replaced by a single space, unless they are part of a
string in double quotes
tabs are replaced by a single space
leading spaces before the first command line argument are ignored
#Jon's :parse/:endparse scheme is a great start, and he has my gratitude for the initial pass, but if you think that the Windows torturous batch system would let you off that easy… well, my friend, you are in for a shock. I have spent the whole day with this devilry, and after much painful research and experimentation I finally managed something viable for a real-life utility.
Let us say that we want to implement a utility foobar. It requires an initial command. It has an optional parameter --foo which takes an optional value (which cannot be another parameter, of course); if the value is missing it defaults to default. It also has an optional parameter --bar which takes a required value. Lastly it can take a flag --baz with no value allowed. Oh, and these parameters can come in any order.
In other words, it looks like this:
foobar <command> [--foo [<fooval>]] [--bar <barval>] [--baz]
Complicated? No, that seems pretty typical of real life utilities. (git anyone?)
Without further ado, here is a solution:
#ECHO OFF
SETLOCAL
REM FooBar parameter demo
REM By Garret Wilson
SET CMD=%~1
IF "%CMD%" == "" (
GOTO usage
)
SET FOO=
SET DEFAULT_FOO=default
SET BAR=
SET BAZ=
SHIFT
:args
SET PARAM=%~1
SET ARG=%~2
IF "%PARAM%" == "--foo" (
SHIFT
IF NOT "%ARG%" == "" (
IF NOT "%ARG:~0,2%" == "--" (
SET FOO=%ARG%
SHIFT
) ELSE (
SET FOO=%DEFAULT_FOO%
)
) ELSE (
SET FOO=%DEFAULT_FOO%
)
) ELSE IF "%PARAM%" == "--bar" (
SHIFT
IF NOT "%ARG%" == "" (
SET BAR=%ARG%
SHIFT
) ELSE (
ECHO Missing bar value. 1>&2
ECHO:
GOTO usage
)
) ELSE IF "%PARAM%" == "--baz" (
SHIFT
SET BAZ=true
) ELSE IF "%PARAM%" == "" (
GOTO endargs
) ELSE (
ECHO Unrecognized option %1. 1>&2
ECHO:
GOTO usage
)
GOTO args
:endargs
ECHO Command: %CMD%
IF NOT "%FOO%" == "" (
ECHO Foo: %FOO%
)
IF NOT "%BAR%" == "" (
ECHO Bar: %BAR%
)
IF "%BAZ%" == "true" (
ECHO Baz
)
REM TODO do something with FOO, BAR, and/or BAZ
GOTO :eof
:usage
ECHO FooBar
ECHO Usage: foobar ^<command^> [--foo [^<fooval^>]] [--bar ^<barval^>] [--baz]
EXIT /B 1
Yes, it really is that bad. See my similar post at https://stackoverflow.com/a/50653047/421049, where I provide more analysis of what is going on in the logic, and why I used certain constructs.
Hideous. Most of that I had to learn today. And it hurt.
Batch Files automatically pass the text after the program so long as their are variables to assign them to. They are passed in order they are sent; e.g. %1 will be the first string sent after the program is called, etc.
If you have Hello.bat and the contents are:
#echo off
echo.Hello, %1 thanks for running this batch file (%2)
pause
and you invoke the batch in command via
hello.bat APerson241 %date%
you should receive this message back:
Hello, APerson241 thanks for running this batch file (01/11/2013)
Use variables i.e. the .BAT variables and called %0 to %9

Resources