comment – rem (which will show that to the user but not execute) or #
data entry, ask for – SET /P IP= IPADDRESS: will present user with “IPADDRESS” and put it into a variable called %IP%
DNS server, set – note below that both “local” as a generic reference to your main network connection as well as “Local area connection” referring to the named connection both work
netsh interface ip set dns local static 192.168.254.13 primary
netsh interface ip add dns "Local area connection" 192.168.254.19
DNS service, restart
net stop "DNS Client"
net Start "DNS Client"
echo – repeat what you say after “echo” to the monitor
@echo off – after you issue this command, the “C” prompt won’t show up
environment variables – a list. To see all the variables, type: set
Some samples
Variable |
Type |
Description |
%COMPUTERNAME% |
System |
Returns the name of the computer. |
%DATE% |
System |
Returns the current date. Uses the same format as the date /t command. Generated by Cmd.exe. |
%ERRORLEVEL% |
System |
Returns the error code of the most recently used command. A non zero value usually indicates an error. |
%OS% |
System |
Returns the operating system name. Windows 2000 displays the operating system as Windows_NT. |
%PATH% |
System |
Specifies the search path for executable files. |
%SYSTEMDRIVE% |
System |
Returns the drive containing the Windows XP root directory (that is, the system root). |
%SYSTEMROOT% |
System |
Returns the location of the Windows XP root directory. |
%TEMP% and %TMP% |
System and User |
Returns the default temporary directories that are used by applications available to users who are currently logged on. Some applications require TEMP and others require TMP. |
%TIME% |
System |
Returns the current time. Uses the same format as the time /t command. Generated by Cmd.exe. |
%USERDOMAIN% |
Local |
Returns the name of the domain that contains the user's account. |
%USERNAME% |
Local |
Returns the name of the user who is currently logged on. |
%WINDIR% |
System |
Returns the location of the operating system directory. |
gateway, set – need to set IP address, mask and gateway metric (the “1” at the end) as well. If you set the gateway, the gateway metric is not optional.
netsh interface ip set address "Local Area Connection" source=static 192.168.254.43 mask=255.255.255.0 gateway=192.168.254.254 1
IP address, set dynamic –
netsh interface ip set address "Local Area Connection" source=dhcp
IP address, set fixed – need to set mask as well. The last two argument – gateway, and gateway metric (the “1” at the end) – are optional
netsh interface ip set address "Local Area Connection" source=static 192.168.254.43 mask=255.255.255.0 gateway=192.168.254.254 1
variable set – put variable name followed immediately by “=” and the value. Can’t have spaces. Well, you can, but then the space becomes part of the variable name itself. For example:
set test=9
set test = 9
run set and you’ll see:
test=9
test = 9
where “test” is set to “9” and “test ” is set to “ 9”
Note that variable names are surrounded by percent signs when they're used but not when they're set (assigned).
variables, environment – see environment variables