Useful Command-line Commands on Windows

The aim for this Wiki is to promote using a command to open up commonly used applications without having to go through many mouse clicks - thus saving time on monitoring and troubleshooting Windows machines.

• Application name
• Commands
• Screenshot (Optional)

Shortcut to commands

locked by ZypherDec 11 '11 at 21:18

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. See the help center for guidance on writing a good question.

• If you find this stuff interesting, take a look at commandlinefu: commandlinefu.com It's basically like digg for CLI – username May 11 '09 at 6:47
• great list, very usefull – Adyt May 20 '09 at 8:56
• Try putting each command as a separate answer. Then we can vote and comment on each one. – lamcro Jun 26 '09 at 12:22
• This is a great question, super useful info, and the stackexchange engine made it trivial to find. I agree with @lamcro, however, that structuring each command as an individual answer would likely provide more value, however then the wouldn't be sorted alphabetically? hmmm... – David Alpert Jul 29 '09 at 22:00
• This is a great example, across all SE, of a well-executed poll. I especially like combining separate answers (for voting) and alphabetical index to them! – Jonik Sep 17 '10 at 14:16

To quickly open the Exchange 2007 Management Shell:

exshell.psc1


Active Directory Sites and Services:

dssite.msc


Basically, anything in the start menu I try to grab the properties of the shortcuts and find out what they actually call.

Oh, and the "elevated" command-prompt in Vista:

Start -> from the Search box "cmd" + Ctrl+Shift+Enter

:)

perfmon


Opens up Windows Performance Monitor.

The key combination . . . notepad will show all files in the directory, use the up and down key to select, then enter to execute the command. Very useful for lazy typers like myself.

getmac


dsa.msc - opens active directory users and computers.

whoami /all


Used to be reskit.

qfecheck
for Server 2003,2000 & XP - Does not apply to Server 2008, Vista or Win7(as far as I know)

Shows installed Hotfixes applied to the server/workstation.

More detail at -> http://support.microsoft.com/kb/282784

Usage:

Lists all shadow copies in the system, grouped by shadow copy set Id.

Lists all writers in the system

Lists all currently installed shadow copy providers


vssadmin is essential to troubleshooting backup products that use vss. With vssadmin you can check writer status, and list all outstanding shadow copies on a volume. Very handy.

I particularly like pushd and popd for directory navigation via stack. Not only can they change the current folder, they can also change the current drive. (cd /d can do this too.) What's more, if you try to pushd to a UNC path, the shell will automatically map the share to a drive letter starting from Z and working backwards. When the matching popd is called, the drive is unmapped automatically.

A particularly useful aspect of netsh that I think is worth a mention: netsh winsock reset This was added in XP service pack 2 to reset the tcpip implementation back to its defaults. In versions prior to XP, this was accomplished by uninstalling and reinstalling TCP/IP. Prior to SP2 you either needed the winsockxpfix.exe application or an ugly method of ripping out tcp/ip and reinstalling it. This command can correct issues where tcp/ip becomes corrupted for whatever reason.

Also, the HELP command lists a whole slew of other commands that can be of use.

net user {username} {newpass}


map a network drive

net use z: \\servername\sharename /user:username

1. mspaint

1. msconfig :-System Configuration Utility

5.sshclient

6.%temp%

Command to abort the shutdown process.

c:\shutdown -a

Sound

The command

mmsys.cpl


opens

Date and Time

The command

timedate.cpl


opens

Windows Security Center

wscui.cpl


opens

tracert

Usage: tracert [-d] [-h maximum_hops] [-j host-list] [-w timeout] target_name

Options:

-d                 Do not resolve addresses to hostnames.

-h maximum_hops    Maximum number of hops to search for target.

-j host-list       Loose source route along host-list.

-w timeout         Wait timeout milliseconds for each reply.


The items in the following list might be duplicates, but I just want to add it just in case (this is from a buddy's list). This might be more useful to an office worker than to a system administrator though:

1. devmgmt.msc = Device Manager
2. msinfo32 = System Information
3. cleanmgr = Disk Cleanup
4. ntbackup = Backup or Restore Wizard (Windows Backup Utility)
5. mmc = Microsoft Management Console
6. excel = Microsoft Excel (If Installed)
7. msaccess = Microsoft Access (If Installed)
8. powerpnt = Microsoft PowerPoint (If Installed)
9. winword = Microsoft Word (If Installed)
10. frontpg = Microsoft FrontPage (If Installed)
13. calc = Calculator
14. msmsgs = Windows Messenger
15. mspaint = Microsoft Paint
16. wmplayer = Windows Media Player
17. rstrui = System Restore
18. netscp6 = Netscape 6.x
19. netscp = Netscape 7.x
20. netscape = Netscape 4.x
21. waol = America Online
22. control = Opens the Control Panel
23. control printers = Opens the Printers Dialog

pathping - a traceroute that collects detailed packet loss statistics.

Behold:

command.com


Very often would I see the system being plagued by trojans/worms that attempt to lock down every way of getting through to system internals like regedit, mmc, cmd.exe, etc. Then you have no choice, but to boot from a live CD. But, obviously, with command.com at your disposal you can do anything you want, and I've yet to see THAT made unavailable.

Get the current day, month and year into environment variables (adjust for locale).

Command line:

for /f "tokens=2,3,4 delims=/ " %a in ('echo %date%') do set mon=%a && set day=%b && set year=%c


Or in a batch file:

for /f "tokens=2,3,4 delims=/ " %%a in ('echo %date%') do set mon=%%a && set day=%%b && set year=%%c


Other stuff

ipconfig /displaydns

WMIC - command line access to WMI

dsqery, dsget, dsmod, dsadd - command line access to AD

net localgroup

for /f %%a (' some command ') do call :sub %%a

Use :: instead of REM in batch files.

nbtstat

NTRIGHTS.EXE grant sePriveleges

Set /P for prompting.

IF ELSE in batch:

IF EXIST filename. (
del filename.
) ELSE (
echo filename. missing.
)

• Thanks for ipocnfig /displaydns, I did not know about that one. It seems like it could be useful. – railmeat Aug 11 '09 at 2:24

Use

httpcfg [query | set | delete] iplisten [ip address]


to find out or change the IP addresses IIS is listening on

(If you want to run IIS and some other HTTP server on the same box and port with different IP addresses.)

While it's from Sysinternals, the sysinternals tools are so essential and commonly installed on servers they might as well be part of the OS.

psexec \\targetserver -w "d:\bin" "cmd"


You now have an interactive shell on a remote computer. Enter "exit" to come back home. I will often use it to apply something to a group of servers as follows.

set srvs=server1 server2 server3
set execthis=[something useful]
for %s IN (%srvs%) DO (
start psexec \%s -u domain\someUser -p superSecretOfCourse "cmd" "/C %execthis%"
)


Here I show several handy tricks:

1. Use for loops to execute a command multiple times (from batch use %%s instead of %s)
2. Start to open a window in a new process - handy if each operations takes a few minutes.
3. Psexec can use windows auth or a login. Noting that integrated auth usually won't hop from local to server to a third location (e.g. SAN) - provide user and password if you need to access a network resource
bootsect.exe {/help | /nt52 | /nt60} {SYS | ALL | <DriveLetter:>} [/force]


Bootsect.exe updates the master boot code for hard disk partitions to switch between BOOTMGR and NTLDR. You can use this tool to restore the boot sector on your computer.

Mind you that this tool is only available on the Windows installation DVD under the BOOT folder. (I think only Windows Vista or higher.)

print %logonserver%

A very quick and easy way to view the DC that your workstation has authenticated against. Useful when working with GPO's and scripts.

• PRINT? Not ECHO? – jscott Dec 11 '11 at 15:24
Disk Management
diskmgmt.msc


Opens

Keyboard Properties
control keyboard


Opens

Regional and Language Options
intl.cpl


Opens

Internet Properties
inetcpl.cpl


Opens

It is always fun to create a macro that performs a quick and unconditional format of a disk:

doskey cd=format \$1 /q /u


Then to format a disk in drive A type:

cd A:

• Shame they dropped the format's /autotest parameter. ;) – macbirdie May 6 '09 at 6:55