Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

Running wmic

wmic is a shell command similar to netsh, covered in Chapter 11, “Configuring Windows 7 with netsh.” You can enter wmic from the command prompt to enter the wmic shell. The wmic shell prompt starts in the root\cli name space, from which you can then enter commands. For example, if you want to get detailed information on the computer, you can use the computersystem list full command:

C:\>wmic
wmic:root\cli>computersystem list full

You can also enter the full wmic command from the command prompt by preceding it with wmic. For example, the following command provides the same output as the previous command:

C:\>wmic computersystem list full

If you were writing this within WMI (not wmic), you would have to understand the query language, and the query would look something like this:

Select * from Win32_ComputerSystem

However, thanks to the wmic built-in aliases, you don’t have to learn the query language to use wmic.

The wmic command includes several switches. Some of the more common switches are listed in the following table.

Tip

Some commands don’t recognize the switch unless it is entered before the command (right after wmic) rather than after the command (at the end of the wmic command string).


SwitchDescription
/? [:brief | :full]
C:\>wmic /?
C:\>wmic /?:full

Shows the syntax of all global switches and aliases. The default listing is brief, but you can also specify full to get a more verbose listing of help.
/node:remotecomputer
wmic /node:remotecomputer command
C:\>wmic /node:win7pcg computersystem
C:\>wmic /node:win7pcg printer list brief

You can use the /node switch to retrieve information from any remote computers. The first example retrieves information with the computersystem alias, and the second example uses the printer alias.
/user:username
wmic /node:remotecomputer /user:username
command
C:\>wmic /node:win7pcg /user:pearson
\administrator computersystem

Provides the username to be used during the session or for the command. You will be prompted to enter a password. This is useful when connecting to remote systems, but it can’t be used to change the credentials on the local system.
/password:password
wmic /node:remotecomputer /user:username
/password:password command
C:\>wmic /node:win7pcg /user:pearson
\administrator /password:P@ssw0rd
computersystem

Provides the password to be used with the specified user. This command must be used with a username.
/output:target [stdout | clipboard | file
path and name]
wmic /node:remotecomputer /output:target
command
C:\>wmic /node:win7pcg /output:clipboard
computersystem
C:\>wmic /node:win7pcg /output:filename
computersystem
C:\>wmic /node:win7pcg /output:c:\
scripts\test.txt computersystem

Identifies where to redirect the output. The output is normally sent to the screen but can be sent to the Clipboard or to a file. The /output switch needs to go before the alias.

When sending it to a file, the path must exist or the command will fail with an “Invalid file name” error.

Tip

The normal redirect symbol (>) can also be used, as in the following example:

C:\>wmic /node:win7pcg com-
putersystem > c:\scripts\
test.txt

/append:target [stdout | clipboard | file
path and name]
C:\>wmic /node:remotecomputer
/append:filename command
C:\>wmic /node:win7pcg /append:c:
\scripts\test.txt computersystem

Identifies where to redirect the output.

If the file doesn’t exist, it will be created. If it does exist, the output is appended to the file.

When sending it to a file, the path must exist or the command will fail with an “Invalid file name” error.

Note

The /append switch sends the data to the file and to the screen.