WMI classes are base of Windows management, however many administrators dont know how to use their potential. That is why I decided to write this series of articles…
WMI classes are between you (wscript/cscript, console etc.) and system APIs. They provide access to almost everything you need to know. For example informations about memory, CPU, processes, services, filesystem etc.
In w2k only method to access this classes was by using scripts (vbscript), so they were great for scripting, however it was hard to use them if you wanted just to receive some informations. Someone clever at Microsoft had nice idea – what about creating cmd utility, that would provide access to these classes? You want need to create big program and you will have access to many interesting informations.
And that is why WMIC was created. As I said this will be really soft introduction, so I will start with classes/objects/methods/properties. You can encounter these terms in almost every programmers documentation, however what do they really mean?
Everything in windows is object – file is object, directory is object, user is object etc… Every object have properties and methods. Method mean “do something”, while property is just the value.
Lets take example – our object will be dog. He have methods (”Bark”, “Roll”, “ShutUp” etc.) and properties (value of property “Color” will be “Black”, value of property “Tail” will be “Short” etc.).
Classes are something like templates for objects – they specify, what methods/properties the object will have and how they will act. Example: lets say you are architect. You created blueprint for house – however it is just blueprint. When you will build house, you will take this blueprint and modify it – for example you will say that walls will be white, it will have an alarm etc. So your object WONT affect the class.
When you create object, it is created from class. Class Dog only says that every dog have property Legs, Tail etc and methods Bark etc. You initiate the object when you say that Fred is Dog – from now Fred have properties/methods based on dog class. You cant ask whats the color of dog in general – you can ask what is the color of Fred.
Sometimes you need (or you can) provide arguments to methods – for example Fred.Bark(Loud) or Fred.ShutUp(Now)… Sometimes you can provide more arguments, for example Fred.Bark(Loud,5), where you are telling Fred to bark, volume Loud and do it for 5 minutes.
Now lets return to WMIC. In WMIC you are using aliases to access classes. For example to access processes, you wont use Win32_Process (WMI Class), you use just Process (Alias).
Basic syntax of WMIC is “WMIC Alias WMIC_Method Parameters).
There are 4 WMIC methods:
- list – retrieve a set of properties
- get – retrieve specific property(properties)
- set – set a property value
- call – call a method
For example to view properties of process, you use command “WMIC process list”. To set property you use “WMIC Process set property_name=property_value”. To call method you use “WMIC process call method_name” etc…
How do you know what aliases you have available? And how do you know their properties/methods?
There is switch /? available. If you want to see all available aliases, just use command “WMIC /?”.
This switch is also available for aliases, so if you want to see available methods of alias process, use command “wmic process call /?”. If you want to see properties, use “wmic process get /?”.
This switch (/?) have two modes – brief and full. Brief is default, if you need more informations (for example description of properties), use full method. Syntax is /?:help_mode.
For example to see everything about process methods, use command “wmic call /?:full”.
This is just the beginning – next time I will speak about more practical things. Hope so you will play with wmic 🙂