Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


March 2002

WMIC


RSS
Subscribe to Windows IT Pro | See More Windows Management Instrumentation (WMI) Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

Take command-line control over WMI

Microsoft is creating a lot of good reasons to make the command prompt in Windows XP and the Windows .NET Server family your home for systems management. Windows Management Instrumentation Command-line (WMIC), which uses the power of Windows Management Instrumentation (WMI) to enable systems management from the command line, is one of those reasons.

WMI has been an important part of Microsoft's systems management initiative since Microsoft Systems Management Server (SMS) 2.0 and has grown in popularity since the introduction of Windows 2000. However, until the introduction of WMIC, you couldn't easily access the WMI repository or the WMI namespace from a command prompt.

What Is WMIC?
WMIC extends WMI for operation from several command-line interfaces and through batch scripts. Before WMIC, you used WMI-based applications (such as SMS), the WMI Scripting API, or tools such as CIM Studio to manage WMI-enabled computers. Without a firm grasp on a programming language such as C++ or a scripting language such as VBScript and a basic understanding of the WMI namespace, do-it-yourself systems management with WMI was difficult. WMIC changes this situation by giving you a powerful, user-friendly interface to the WMI namespace.

WMIC is more intuitive than WMI, in large part because of aliases. Aliases take simple commands that you enter at the command line, then act upon the WMI namespace in a predefined way, such as constructing a complex WMI Query Language (WQL) command from a simple WMIC alias Get command. Thus, aliases act as friendly syntax intermediaries between you and the namespace. For example, when you run a simple WMIC command such as

useraccount list brief

from the WMIC command prompt to get user account information, the Useraccount alias performs a WQL query of the Win32_Useraccount class and displays specific data from this class in text format. WMIC also displays the Win32_Useraccount class's properties at the console in text format. WMIC can return the results of a command in other formats, such as XML, HTML, and Comma Separated Value (CSV).

WMIC stores aliases as instances of a class in the WMI schema. The default alias classMSFT_CliAlias—and other classes that support WMIC are stored in the schema's default namespace, or role—root\cli. Think of a role as simply another WMI namespace that's specifically designed to support WMIC. The default role, root\cli, connects to the root\cimv2 namespace to operate on the classes within root\cimv2. You won't typically use CIM Studio when you run WMIC, but you can use CIM Studio to find the root\cli namespace in a list of WMI namespaces. Figure 1, page 70, shows the root\cli node and some of the properties in the MSFT_CliAlias class.

You can add new aliases to the root\cli namespace and to other namespaces. You can also access the WMI namespace directly with the Class and Path commands. Later in this article, I show you how to use these commands.

How to Run WMIC
To invoke the WMIC command prompt, type

wmic

in the standard XP or .NET Server command interpreter (cmd.exe), a Telnet session, or the Run dialog box. These startup methods are available locally or through a .NET Server Terminal Services session.

The first time you start WMIC, Windows installs it on the computer and displays the WMIC command prompt, wmic:root\cli>. At this prompt, you enter commands interactively. For example, the command

process where name='outlook.exe'
  call terminate

closes Microsoft Outlook if it's running. After the command runs, the WMIC command prompt reappears. Note that you must type each command in this article on one line, not split across multiple lines, for the commands to run properly. (Some commands in the tables and listings in this article are split across multiple lines for publication purposes.)

WMIC also runs in noninteractive mode. This mode is especially useful when you need to complete a single task or you need to run WMIC commands in a batch file. To run a command in noninteractive mode, you start WMIC and run the command in the same line of code. For example, you can open a command prompt and type

wmic /node:SERVER1
  printer list status

to check the status of printers attached to SERVER1. In this example, WMIC starts, uses the /node switch to establish a remote connection to SERVER1, and runs a command to display printer status information. After the command runs and displays results, the command prompt reappears.

You can remotely access any WMI-enabled computer from any computer running WMIC. The computer you want to access doesn't require WMIC. For example, you can start WMIC from a computer running XP Professional Edition to manage a mix of computers running XP, Win2K, Windows NT 4.0, Windows Me, and Windows 9x.

WMIC Command-Line Components
WMIC uses global switches, aliases, verbs, commands, and command-line help to empower the interface. Global switches are settings that apply to and for the entire WMIC session. For example, the /trace:on switch enables error tracing. While this switch is on, WMIC returns error information for every command you execute. The /node switch lets you access a remote computer. The /interactive:on switch ensures that WMIC prompts you for confirmation before performing delete operations. Other global switches include /role, /user, /implevel, and /namespace.

As I explained earlier, aliases are the friendly syntax intermediaries between you and the WMI namespace. Verbs are the actions you want to take when specifying an alias. I've already shown you the List and Call verbs. Table 1 describes the other WMIC verbs and provides a sample command for each one.

   Previous  [1]  2  Next 


Reader Comments
<br><br>
Most of the command listing are failing.<br>
This is system are not running ms_409 locale.<br>
Run WMIC.<br>
then run /CONTEXT to verify.<br>
To change the locale. run WMIC. Then run /LOCALE:ms_409.<br><br>

This correct the error:<br>
ERROR:<br>
Code = 0x8004100e<br>
Description = Invalid namespace<br>
Facility = WMI<br>
<br><br>
----------------------------------------
<br><br>

<i>The error suggests that the reader is not running the American English localized version
of Windows XP. The /LOCALE:ms_409 text in his error message means that he is running a language of origin that is something other than American English. Perhaps his .NET Server computers are localized to American
English? If he is running an American English localized version, then for some other reason the \root\wmi\MS_409 namespace is missing. The
easiest way to find out whether the namespace is there is by running CIM Studio, connecting to the root namespace and checking that the
\root\wmi\MS_409 child namespace is present.
<br><br>
From MSDN: "Localized classes are organized in child namespaces of the namespace containing the original class. Classes for a given locale are
found in the MS_XXX child namespace, where XXX represents the hexadecimal locale identifier (LCID) for that locale.An amended class,
localized for American English, is found in the \root\wmi\MS_409 namespace.
<br><br>
The reader should refer to the following white paper for more information:
<A HREF="http://www.microsoft.com/windows2000/techinfo/howitworks/management/WMIgloba.asp">http://www.microsoft.com/windows2000/techinfo/howitworks/management/WMIgloba.asp</A>
<br><br>
-Ethan </i>

Roar Skaare March 03, 2002


Dear Mr. Wilansky,

Your article from Windows & .net magazine from March 2002 issue caught my attention.

I am the last year student of Bachelor of Information Technology program from Kwantlen University College (BC, Canada). Your coverage of wmic command helped me a lot to explore Windows architecture. Now from command line I can browse MS classes. I use Windows XP for more than six month. I check MSDN site regularly but I have not found any thing even close with that level of explanation.

However, I have found in the help file the following statement

"You can query for useful computer troubleshooting information, such as installed software."

I tried several switches but I could not get it working. Can you please provide me with some kind simple example how to do it?<br><br>
---------------------------------------------
<br><br><i>Hi Alex:

I'm glad that you found the article useful. I'm also surprised at the lack of documentation on WMIC. Here is a URL to a WMIC reference that you might find useful:

http://www.microsoft.com/technet/treeview/default.asp?url=/TechNet/prodtechnol/winxppro/proddocs/WMIC_Overview.asp
I'm sure that more information about WMIC will be appearing with the release of the Windows .NET Server family.

<P>Here is a command for displaying installed software at the console:

<ol>
<li>Display brief information to the console on each software element:

<pre>softwarefeature list brief /format:textvaluelist.xsl</pre></li>
</ol></P>

You can also change the brief switch to full in order to see more information on installed software, such as when the software was last used.

Thanks,

Ethan
</i><br><br>
--------------------------------
<br><br>Thanks for reply.

I tried your hint. Even with brief switch, I receive quite long list including all original Windows executables.

Is any way that I can target on my or remote computers programs listed in the Control Panel under Add/Remove programs?<br><br>
-------------------------
<br><br><i>Hi again, Alex. While the information I gave you about extracting software information was correct, there is an even easier way to do it with WMIC. Try this command at the WMIC command prompt:

<pre>Product list brief</pre>

Remove the brief switch for more information.

Here's another way to extract specific information about one application:

<pre>product where (name = "Microsoft Office 2000 SR-1 Premium") get</pre>

Ethan</i><br><br>

Alex Polissky June 04, 2002


The wmic tool sounds very tempting. Unfortuntely, our environment is still a mixed NT/W2K network - no XP clients.
My question is: Will the wmic tool be ported over to W2K? I'd love to use it, but have not been able to "copy" it over to W2K. Thanks for any suggestions!


Nathan Emerson November 01, 2002


You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
Friday at PASS Europe 2006

Kevin talks about the closing day of the event and shares a funny Microsoft film. ...

More fun TechEd 2005 Resources

Kevin points out some more TechEd resources ...

What service packs and fixes are available?

...


Related Articles Get Hotfix Information Quickly with WMIC

Windows OSs Whitepapers Why SaaS is the Right Solution for Log Management

Are You Satisfied?

A Preliminary Look at Deployment Plans for Microsoft Windows Vista

Related Events Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.

Job Openings in IT


ADS BY GOOGLE SPONSORED LINKS FEATURED LINKS

Microsoft Exchange & Windows Connections event returns to Las Vegas Nov 10 - 13
Connections returns to Las Vegas for this exciting event where each attendee will receive SQL Server 2008 standard with 1 CAL. Co-located with Microsoft ASP.NET, SQL Server, and SharePoint Connections with over 250 in-depth sessions.

Free Online Event! Virtualization:Get the Facts!
Register now and attend this free, live in-depth online conference on November 13 and 20, 2008, produced by Windows IT Pro. All registrants are eligible to receive a complimentary one-year digital subscription to Windows IT Pro (a $49.95 value)!

Check Out Hyper-V Video on ITTV
Watch Karen Forster's interview on Hyper-V's performance on ITTV.net.

Ease Your Scripting Pains with the Flexibility of PowerShell!
Join MVP Paul Robichaux on December 11, 2008 at 11:00 AM EDT as he equips you with PowerShell basics in 3 introductory lessons, each followed by a live Q&A session—all on your own computer!

PASS Community Summit 2008 in Seattle on Nov 18-21
The don’t-miss event for Microsoft SQL Server Professionals. Register now and you’ll enjoy top-notch Microsoft and Community speakers and more.



Solving PST Management Problems
In this white paper, read about the top PST issues and how to administer local/network PST Files.

Get Protected -- Data Protection Manager 2007
Protect your virtualized environment with Data Protection Manager

Order Your SQL Fundamentals CD Today!
Learn how to use SQL Server, understand Office integration techniques and dive into the essentials of SQL Express and Visual Basic with this free SQL Fundamentals CD.

Maximize Your SharePoint Investment: Get Your Data Moving
Watch this web seminar now to learn how to maximize your SharePoint investment! Join us as we take a look at the complex business of securing, accessing and managing vast amounts of information in a global network and various ways to get your data moving.
Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing