Batch Howtos
29/07/2009 09:26Batch HowTos
On this page you'll find a shorthand list of common tasks in batch files, and the command(s) that can be used to perform those tasks.
Notes: | Many, if not most, of the commands listed here require Windows 2000 and later, some require Windows XP or later, some require Active Directory. Read more detailed information by following the links provided. |
Depending on the Windows version, some commands (e.g. SETX and NETSVC) may require installation of a Resource Kit. |
Task | Available command(s) or variable(s) |
---|---|
Add/remove computer to/from domain | NETDOM (1) |
Counters | FOR /L or SET /A counter += 1 |
Delays | PING |
Current date | DATE /T or %Date% or DEBUG |
Current directory | CD or %CD% |
Current drive | %CD:~0,2% |
Current time | TIME /T or %Time% or DEBUG |
Directory of current batch file | %~dp0 |
Drive of current batch file | %~d0 |
Environment, permanent changes | SETX (2) |
Firewall configuration | NETSH |
Harddisk & volume management | DISKPART, FDISK, FORMAT, CONVERT, MOUNTVOL, VOL, CHKDSK, CHKNTFS, DEFRAG |
Hardware inventory | WMIC |
IP address (local) | PING %ComputerName%, NSLOOKUP %ComputerName% or IPCONFIG /ALL |
IP address (remote) | PING, NSLOOKUP or WMIC |
IP address (WAN) to file | WGET -O output_filename -q https://www.whatismyip.com/automation/n09230945.asp (3) |
IP address (WAN) to screen | WGET -q -O- https://www.whatismyip.com/automation/n09230945.asp (3) |
Logoff | Multiple commands available |
Open a file, folder or web page | START |
Permissions | CACLS, XCACLS (2), MMC & SECEDIT, SUBINACL (3) or SETACL (3) |
Popup dialogs | NET Send %ComputerName% |
Print text | NOTEPAD /P |
Print anything | ASSOC, FTYPE & REGEDIT or REG |
Printer management | RUNDLL32 PRINTUI.DLL,PrintUIEntry |
Process management | Multiple commands available |
Prompt for user input | SET /P & more |
Read text files | FOR /F or occasionaly < redirection |
Reboot | Multiple commands available |
Registry | REGEDIT or REG |
Service management | NET Stop, NET Start, SC or NETSVC (2) |
Shutdown | Multiple commands available |
Unicode to ASCII conversion | TYPE |
User/group management | NET, DSADD, DSGET, DSMOD, DSMOVE, DSQUERY & DSRM (1) or CSVDE & LDIFDE (1) |
Write text files | Redirected ECHO |
Notes: | (1) | Requires Windows XP with Windows Server 2003 Administration Tools Pack, or Windows Server 2003 or later. |
(2) | Resource Kit tool | |
(3) | Third party tool |
———
Back