Command line arguments in the command prompt with examples!
For parameters that can be passed when the batch file is called and other variables via the set on Windows 11, 10, ... and MS Server OS!
Everyone who likes to use variables
and work with arguments
is familiar with these possibilities and likes to benefit from the advantages under all operating systems and not only under Microsoft Windows 11/10 and MS Server OS!
1.) Command line arguments in the command prompt!
Batch Scripts / Command Prompts support command line arguments where arguments can be passed to the batch file when invoked. The arguments can be called from the batch files via the variables %1,%2,%3, ... etc.
If the above batch script is saved in a file called test.bat and execute the batch, for example via a Windows shortcut and use arguments!
Test.bat one two three
When the batch file is executed, these values can be output
( ... see Image-1 Point 1 to 3
| (Image-1) Command line arguments in the command prompt example
2.) Use variables in the command prompt cmd.exe!
The other way variables can be initialized is with the 'set' command. The following is the syntax of the set command .
set message=Hello how are you
In the example above, a variable called message is defined and given the value "Hello how are you".
Note that the variable must be enclosed in % signs in order to display the value of the variable.
EXAMPLE 2: Working with Numerical Values
In the batch script it is also possible to define a variable that contains a numerical value. This can be done with the switch / A.
The following code shows an easy way how numeric values can be used with.
SET /A a = 5
SET /A b = 10
SET /A c = %a% + %b%
| (Image-2) Command line arguments Use numerical values!
3.) Local and global variables, understand the difference!
In every programming language there is an option to mark variables with a range, that is, the section of code that can be accessed. Typically, variables with a global scope can be accessed anywhere from a program, while variables with a local scope have a defined limit at which they can be accessed.
Example of global and local variables
set globalvar = 5
set var = 13145
set / A var =% var% + 5
| (Image-3) Local and global variables!
FAQ 103: Updated on: 26 August 2023 10:52
It is easy to start a connection to the Remote Desktop Service via the command prompt with arguments on Windows 11, 10, and MS Server OS Contents:
Often you want to stop the script in the batch file and wait for the user to press Enter, or variables to process on Windows 11, 10, and MS Server OS
It is quite easy to delete files that are younger than a certain date via the command line under Windows 11, 10, and MS Server OS Everyone probably
It is easy to delete all files except the most recent via command line, script or CMD.EXE for Windows 11, 10, and MS Server The most popular script
It is easy to rename files in batches using a script or command prompt in lower and / or upper-case letters on Windows 11, 10, and MS Server OS Everyone
It is quite easy to find out the serial number of your hard disk under Windows 11, 10, or MS Server 2022, at a command prompt There are free hard
Using the command prompt, it is easy to find out the PC serial number and manufacturer under Windows 11, 10, and MS Server OS Everyone has ► read out
»» My question is not there in the FAQ
Keywords: windows, 11, 10, console, command, line, arguments, prompt, examples, parameters, passed, batch, file, variables, contents, Questions, Answers, Software