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

You use commands to control access to WMIC and the WMI namespace. Notice that the last sample command in the table uses Path and the WIN32_USERACCOUNT class rather than the Useraccount alias. Path is a WMIC command that lets you directly access one or more instances in the WMI namespace rather than reaching them through an alias. The Path command is especially useful when no alias exists for the systems management task you want to complete. You can extend WMIC with new aliases and new roles, but using the Path command is easier if you have a firm grasp on the WMI namespace.

WMIC also supports the Class, Context, Quit, and Exit commands. The Class command lets you directly access a class in the WMI schema or create an instance of an existing class. The difference between the Path and Class commands is that the Path command acts on an instance and its properties (e.g., to retrieve management data), while the Class command acts on the class definition. For example, to retrieve all the properties of the WIN32_SOFTWAREELEMENT class, you can type

class WIN32_SOFTWAREELEMENT get

The output to the console is in HTML format. Later, I show you how to use the /output global switch to redirect the output to an HTML file and view the attributes from a Web browser. The Class command with the Assoc verb shows the namespace path to a class and the other classes associated with the class. You can use the Class command to delete a class and to create an instance of a class but not to create a class.

The Context command shows the current settings of the global switches. The Quit and Exit commands simply leave the WMIC command prompt and return you to the previous shell (e.g., the Telnet prompt, the XP command prompt).

Command-line Help is the way to become familiar with WMIC. Table 2 shows the characters to type at a WMIC command prompt to find the specified information.

Putting WMIC to Work
Now that you understand the components of the WMIC command line, let's look at how to run WMIC from a batch file and send output to the console and to an HTML or XML file. When you run WMIC from a batch file, the XP command prompt appears after the commands run. Running WMIC from a batch file lets you repeat common tasks without having to retype a complicated sequence of commands. For example, Listing 1 shows a command you can place in a batch file to display at the console selected processor information about two computers, SERVER1 and SERVER4. The /format switch is verb-specific rather than global because it works with only the Get and List verbs.

WMIC batch files can use variables. Instead of specifying computer names in the batch file, you can specify variables in the format %1, %2, and so on, as Listing 2 shows. You can place this code in a batch file, then when you run it, type one or two computer names after the batch file name. Alternatively, you can create a separate text file that contains a CSV list or a carriage-return-delimited list of computer names. You call the text file with the /node global switch and the text file name with the @ symbol as a prefix. The @ symbol tells the /node switch that the following parameter is a filename, not a computer name.

The console isn't the only place to send results. You can instruct WMIC to send output to a file in XML, HTML, or Managed Object Format (MOF) format. MOF is the native WMI file format for classes and class instances in the WMI repository on a WMI-enabled computer. Listing 3 shows code that directs the output of SERVER4 processor information to an HTML file. The /output global switch instructs WMIC to send the output to file1.htm. The /format verb-specific switch instructs WMIC to transform the native XML output into an HTML form. You can create Extensible Stylesheet Language (XSL) files to format output or use any of the XSL files stored in the \%systemroot%\system32\wbem folder of any computer with WMIC installed. For example, you can use the csv.xsl file to format the output into a CSV list of results, or the htable.xsl file to create an HTML table of results. Figure 2 shows file1.htm open in a Web browser.

Earlier, I mentioned that the default output of the Class command with the Get verb is in HTML format. Therefore, to send output of this type of command to an HTML file, you specify the /output switch without a /format switch, as Listing 4 shows. The /record and /append global switches also let you capture information from the WMIC command line. Use the WMIC Command-line Help facility to find more information about these switches.

To output information in XML format, use the /translate switch and the Basicxml keyword to convert the greater than (>) and less than (<) symbols into meaningful characters in XML. For example, Listing 5 shows how to create raw XML output. You can then import the XML data into a database or some other repository that understands the XML tags in the output. The output created from the code in Listing 5 contains the WMIC command, the command-line request, the target nodes, the context of the global switches, and the command results.

For good reason, WMIC is a key piece of Microsoft's command-line initiative for XP and .NET Server. WMIC enables robust command-line systems-management access to the WMI namespace, wherever WMI is running on the network. The command-line components take a little time to master, but after you do master them, a whole world of systems management lies at your fingertips.

End of Article

   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
Microsoft Kills OneCare, Will Launch Free Security Solution

Microsoft on Tuesday announced that it would retire its $50-a-year security subscription product, Windows Live OneCare, and replace it with a free solution codenamed "Morro." Unlike OneCare, however, Morro will focus only on core anti-malware features and ...

The website is down because someone removed the X-Box

What happens when a manager mistakes a server for a games console. ...

Xbox 360 Overhaul Arrives with New UI, Avatars

Xbox 360 owners who logon to the system's Xbox Live system this morning will receive the most significant functional change yet to the console's user interface, or dashboard. Dubbed the New Xbox Experience, this new front-end features a completely new ...


Related Articles Get Hotfix Information Quickly with WMIC

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

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.


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