command1 & command2
Execute command2 after execution of command1 has finished
command1 && command2
Execute command2 only if execution of command1 has finished successfully
command1 ¦¦ command2
Execute command2 only if execution of command1 has finished unsuccessfully
-----------------------------------------------------------------------------
How do I perform an operation on every machine running on the network?
Normally, you can use a logon script. However, if you want to run a command
or copy a file to every machine, you can use the following command.
FOR /F " tokens=1 " %%i in ('net view') do copy quaropts.dat "%%i\C$\program files\navnt"
-----------------------------------------------------------------------------
To send a message from a batch file, use the Net Send command, as follows.
net send ""
-----------------------------------------------------------------------------
echo | logon savillj
You can also use the following code to echo a return.
echo.|cmd.exe
-----------------------------------------------------------------------------
You can also use the nul command if you want to blank a file, as the
following example shows.
copy nul file.name
-----------------------------------------------------------------------------
A modification of the Microsoft documentation covering the basic batch file
commands for Windows 2000, including CALL, ECHO, ENDLOCAL, FOR, GOTO, IF,
PAUSE, REM, SETLOCAL, SHIFT and variables.
To display a pipe (|) or redirection character (< or >) when using the echo
command, use a caret character immediately before the pipe or redirection
character (for example, ^>, ^<, or ^| ). If you need to use the caret
character itself (^), use two in a row (^^).
startlocal
PATH=c:\onlypath
...
endlocal
-----------------------------------------------------------------------------
Parameter label
Specifies the line in a batch program to which Windows 2000 should go. If
command extensions are enabled (the default setting in Windows 2000), goto
changes as follows: Using the goto command with a target label of :EOF
transfers control to the end of the current batch script file, exiting the
batch script file without defining a label.
Valid values for label
The label parameter can include spaces but cannot include other separators,
such as semicolons or equal signs. When using goto with the EOF label, you
must insert a colon before the label, for example: goto :EOF
Goto uses the first eight characters of each label
The goto command uses only the first eight characters of a label. Therefore,
the labels ":hithere01" and ":hithere02" are both equivalent to ":hithere0."
-----------------------------------------------------------------------------
To change a computer's Domain Name System (DNS) server or servers from the
command line, type:
regfind -p HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\
Tcpip\parameters " old DNS value" -r " new DNS value(s)"
Where old DNS value is the value the server currently has, and new DNS
value(s) is the new value you want to use. The format is dotted decimal
notation.
You can also perform the same operation to a computer remotely by typing the
following command:
regfind -m \\ computer name -p HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\
Services\Tcpip\parameters " old DNS value" -r " new DNS value(s)"
Where computer name is the NetBIOS name or the Internet Protocol (IP) address
of the remote computer.
NOTE: This operation should not require a restart of the computer to make
the changes.
For more information about the Regfind tool and its capabilities, at a
command prompt, type: regfind /?
-----------------------------------------------------------------------------
To lock a workstation programmatically, you can use the Win32 LockWorkStation
function. You can call this function from the command line by using the
Run32dll interface. To lock a workstation from the command line, use the
following command:
rundll32 user32.dll,LockWorkStation
Note that this command is white space sensitive and case sensitive. This
call was introduced in Windows 2000 and is not supported in earlier versions
of Windows.
-----------------------------------------------------------------------------
Use the following syntax to launch Control Panel applications and open
folders:
Control desktop
Launches the Desktop Control Panel subprogram
Control color
Launches the Desktop Control Panel subprogram, with the Appearance
tab preselected
Control date/time
Launches the Date/Time Control Panel program
Control international
Launches the Regional Settings Control Panel subprogram
Control mouse
Launches the Mouse Control Panel subprogram
Control keyboard
Launches the Keyboard Control Panel subprogram
Control printers
Displays the Printers folder
Control fonts
Displays the Fonts folder
For Windows 2000:
Control folders
Launches the Folder Settings Control Panel subprogram
Control netware
Launches the Novell NetWare Control Panel subprogram (if installed)
Control telephony
Launches the Phone and Modem Options Control Panel subprogram
Control admintools
Displays the Administrative Tools folder
Control schedtasks
Displays the Scheduled Tasks folder
Control netconnections
Displays the Network and Dial-up Connections folder
Control infrared
Launches the Infrared Control Panel subprogram (if installed)
Control userpasswords
Launches the Users and Passwords Control Panel subprogram
For example, to open the printers folder, type the following at the MS-DOS
command prompt:
control printers
The %Systemroot%\System32 folder also contains .cpl files that allow users
to launch Control Panel applications through Windows Explorer or the command
prompt.
-----------------------------------------------------------------------------
Returns 1 for Windows NT Workstation.
Returns 2 for Windows 2000 Professional.
Returns 3 for Windows NT Server non-domain controller.
Returns 4 for Windows 2000 Server non-domain controller.
Returns 5 for Windows NT Server domain controller.
Returns 6 for Windows 2000 Server domain controller.
Returns 7 for Windows NT Enterprise/Terminal Server domain controller.
Returns 8 for Windows NT Enterprise/Terminal Server non-domain controller.
if Windows_NT == %OS% goto WINNT
echo You are not running Windows NT (Windows 95/98 perhaps?)
goto END
:WINNT
gettype.exe
if ERRORLEVEL=9 goto getype not found
if ERRORLEVEL=8 goto EIGHT
if ERRORLEVEL=7 goto SEVEN
if ERRORLEVEL=6 goto SIX
if ERRORLEVEL=5 goto FIVE
if ERRORLEVEL=4 goto FOUR
if ERRORLEVEL=3 goto THREE
if ERRORLEVEL=2 goto TWO
if ERRORLEVEL=1 goto ONE
Silent mode can be set with the /s parameter. This tool can also be run
against remote computers.
-----------------------------------------------------------------------------
for /f "tokens=*" %%n in ('date /t') do set date=%%n
for /f "tokens=*" %%n in ('date /t') do for /f "tokens=*" %%b in ('time/t') do Echo:Today is %%n and the time is %%b
-----------------------------------------------------------------------------
The Application Compatibility utility (apcompat.exe) lets you run
applications written for earlier Windows versions. Simply fire up the tool,
identify the legacy program you want to run, and enter the Windows version
that you want the OS to report to the application.
The Cipher command-line tool (cipher.exe) lets you encrypt, decrypt, or
display a file or folder's encryption information. You can also use
cipher.exe to find out who has encrypted a specific file or folder.
logoff [/n] [/f]
If you specify the /n option, logoff doesn't present its confirmation
prompt. However, if you have open and unsaved data, your applications still
ask whether you really want to log off. You might want to retain those
application prompts, because batch scripts that kick users off their
machines and lose their data make for lousy administrator-user PR.
But if you don't need the application prompts, you can use the /f option to
force the logoff.
logoff.vbs /s {servername} /u {username} /w {password} /f
-----------------------------------------------------------------------------
file name completion ... quick-search features of the Windows NT command
processor, cmd.exe. When you type a path or a file name and then press TAB,
cmd.exe searches for all files whose path and file name match your entry.
NOTE: Automatic complete for cmd.exe is not enabled by default in Windows
2000 and later.
When you type a path and then press the TAB key, the command processor
searches for all files whose path (but not necessarily the file name)
matches your entry. The command processor displays one of the matching file
names each time you press TAB. To go backward through the list of file names,
press SHIFT+TAB. This article describes how to enable automatic complete for
cmd.exe.
To enable automatic complete for cmd.exe, use Registry Editor (Regedt32.exe)
to view the following registry key:
HKEY_CURRENT_USER/Software/Microsoft/Command Processor
Edit the CompletionChar value, and set the value of REG_DWORD to 9.
Note that you do not need to restart your computer.
-----------------------------------------------------------------------------
The default PIF file for all command environments in which have no PIF
associated with them is:
%systemroot%\_default.pif