WMIC is the abbreviation of Windows Management Interface Command, is a simple command prompt tool that returns information about the system you are running it on. WMIC extends WMI for operation from several command-line interfaces and through batch scripts. Before WMIC, you used WMI-based applications, the WMI Scripting API, or tools such as CIM Studio to manage WMI-enabled computers. 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. The WMIC program can return useful information about your system, control running programs and generally manage just about every aspect of your PC. Show
Common WMIC queriesHow To Find Out The Model Of Your Computer ?In order to find out the model name of a machine using WMI, simply follow the guide below: Go into a command prompt and Type in >WMIC ComputerSystem GET Model then, you will get: Model HP Notebook How to Find Your Computer Name ?>wmic computersystem get name,systemtype output: Name : yourcomputername SystemType : x64-based PC How to Find the Serial Number of your computer ?>wmic bios get serialnumber One more command will help you to identify the Serial Number of your Computer >wmic csproduct get identifyingnumber How to Find the MAC Address of Your Computer ?>wmic nic get macaddress,description How to Check Your Motherboard Model Number ?>wmic baseboard get product,Manufacturer,version,serialnumber How to check physical memory of your computer ?>wmic COMPUTERSYSTEM get TotalPhysicalMemory How to get all running programs and memory usage ?>wmic process get workingsetsize,commandline This lists the program and the memory usage How to get partition name size and type ?>wmic partition get name,size,type How to get computer manufacturer ?>WMIC COMPUTERSYSTEM GET MANUFACTURER output : HP How get mode version ?>wmic computersystem get name,systemtype0 output: Type1ProductConfigId System InformationThis program can also provide details on many other aspects of your system. >wmic computersystem get name,systemtype1 >wmic computersystem get name,systemtype2 >wmic computersystem get name,systemtype3 will list your installed software, services, running processes and Windows startup programs, for instance. Process ManagementUsing WMIC you can manage your computer process like, close all the instances of a particular program. For example, if you want to shut down all FireFox windows, for instance, then the command: >wmic computersystem get name,systemtype4 Write WMIC output to fileIn order to do so, simply use the /output: "< filepath & name >" switch. Insert this right after the wmic, but before any other part of the command: for instance, wmic /output:"C:\output.txt" , then the output will export the output.txt file. Though the C in WMIC seems to stand for Console, I prefer to interpret it as WMI for the Command line. To start WMIC in interactive console mode, just type: WMIC /Output:bios.html BIOS Get Manufacturer,Name,Version /Format:htable START "" "%CD%.\bios.html"8 Typing WMIC /Output:bios.html BIOS Get Manufacturer,Name,Version /Format:htable START "" "%CD%.\bios.html"9 in the WMIC console will give you the same on-screen help you would get after typing: FOR /F "tokens=*" %%A IN ('WMIC BIOS Get Manufacturerˆ,Nameˆ,Version /Value ˆ| FIND "="') DO ( SET BIOS.%%A ) SET BIOS0 at the command prompt: a list of switches and aliases. Since we are dealing with batch files here, I'll use the commands for Command Line Mode from now on. WMIC commands
Now let's try the following commands: WMIC BIOS WMIC BIOS Get Manufacturer WMIC BIOS Get Manufacturer,Name,Version /Format:csv WMIC BIOS Get Manufacturer,Name,Version /Format:list WMIC BIOS Get /Format:list WMIC BIOS Get Manufacturer,Name,Version /Format:htable You may want to save the latter to a HTML file to view it in a browser: WMIC /Output:bios.html BIOS Get Manufacturer,Name,Version /Format:htable START "" "%CD%.\bios.html" Need the result pasted in another window? Use WMIC Path Win32_NetworkAdapter Get0 Need to store the properties in variables? Try this (note the commas now being "escaped" by ˆ, carets): FOR /F "tokens=*" %%A IN ('WMIC BIOS Get Manufacturerˆ,Nameˆ,Version /Value ˆ| FIND "="') DO ( SET BIOS.%%A ) SET BIOS Try to figure out for yourself how that worked. WMIC Path Win32_NetworkAdapter Get1 filtering and without the WMIC Path Win32_NetworkAdapter Get2 loops, and see what the output looks like... Now prepend each of those lines with WMIC Path Win32_NetworkAdapter Get3 Narrowing down the returned selection with WHEREOften WMI queries return far too much information, so we want to narrow down the selection. WMIC Path Win32_NetworkAdapter GetNote:If all you want to know is the number of adapters, just list the indexes only: WMIC Path Win32_NetworkAdapter Get4 WQL to the rescue!WQL or WMI Query Language allows us to get only those instances matching the conditions set by a WMIC Path Win32_NetworkAdapter Get5 clause. The following modified query returns only 2 instances on my computer (it turns out the BlueTooth dongle is also considered a physical network adapter): WMIC Path Win32_NetworkAdapter Where "PhysicalAdapter=TRUE" Get This is pretty straightforward. WMIC Path Win32_NetworkAdapter Where "Manufacturer=Realtek" Get WMIC Path Win32_NetworkAdapter Get6 in this case is a string, so we need to place it in quotes, preferably without confusing them with the quotes for the entire WMIC Path Win32_NetworkAdapter Get5 clause. The following commands will work: WMIC Path Win32_NetworkAdapter Where "Manufacturer='Realtek'" Get WMIC Path Win32_NetworkAdapter Where (Manufacturer='Realtek') Get WMIC Path Win32_NetworkAdapter Where (Manufacturer="Realtek") Get WMIC Path Win32_NetworkAdapter Where "Manufacturer = 'Realtek'" Get etcetera. Parentheses are required for more complex WMIC Path Win32_NetworkAdapter Get5 clauses: WMIC /Output:bios.html BIOS Get Manufacturer,Name,Version /Format:htable START "" "%CD%.\bios.html"0 However, these parenthesis tend to break your WMIC Path Win32_NetworkAdapter Get9 loops... A limitation of the WMIC Path Win32_NetworkAdapter Get5 clause is that it cannot select properties of type array. Take a good look at WQL if you intend to use WMIC /Output:bios.html BIOS Get Manufacturer,Name,Version /Format:htable START "" "%CD%.\bios.html"8 seriously. A note on aliasesInstead of the BIOS alias, we might just as well have used Path Win32_BIOS, it wouldn't have made any difference. To find the full class name behind an alias, use the following command: WMIC /Output:bios.html BIOS Get Manufacturer,Name,Version /Format:htable START "" "%CD%.\bios.html"1 The result will look like this: WMIC /Output:bios.html BIOS Get Manufacturer,Name,Version /Format:htable START "" "%CD%.\bios.html"2 or use: WMIC /Output:bios.html BIOS Get Manufacturer,Name,Version /Format:htable START "" "%CD%.\bios.html"3 The result will be one or more lines like this: WMIC /Output:bios.html BIOS Get Manufacturer,Name,Version /Format:htable START "" "%CD%.\bios.html"4 To list all available aliases, try this short batch file: WMIC /Output:bios.html BIOS Get Manufacturer,Name,Version /Format:htable START "" "%CD%.\bios.html"5 Or use WMIAlias.bat, which can either list all aliases and their class names, or return the class for a single specified alias. I have not yet found a way to make WMIC list all WMI classes available, but the following code comes close: WMIC /Output:bios.html BIOS Get Manufacturer,Name,Version /Format:htable START "" "%CD%.\bios.html"6 The first line extracts a list of aliases from WMIC's help screen, and these aliases are "fed" to the second WMIC command line which retrieves the Target class, as discussed above. The resulting list is not sorted and may contain duplicates. By far the easiest and most reliable way to find all WMI classes available is to use Microsoft's ScriptOMatic or my own WMI Code Generator, both with GUI, or ListWMIClasses.vbs. Other computers & other WMI namespacesUse WMIC's WMIC Path Win32_NetworkAdapter Where "PhysicalAdapter=TRUE" Get2 switch to query remote computers. Use WMIC's WMIC Path Win32_NetworkAdapter Where "PhysicalAdapter=TRUE" Get3 switch to query classes that are not located in the default CIMV2 namespace. Work with the registryIt is possible to use WMIC to read, write or delete registry keys and values, but I would not recommend it, it is not for the faint of heart. The reason I still mention this feature of WMIC is the possibility to check if the current user has permissions to access a registry key or value: WMIC /Output:bios.html BIOS Get Manufacturer,Name,Version /Format:htable START "" "%CD%.\bios.html"7 This code will return "errorlevel" 0 ("true") if the current user has permission to set values in WMIC Path Win32_NetworkAdapter Where "PhysicalAdapter=TRUE" Get4 or 2 ("false") if not. To combine permissions, add their associated hexadecimal numbers. Note:You don't have to use environment variables to store the hexadecimal values:WMIC Path Win32_NetworkAdapter Where "PhysicalAdapter=TRUE" Get5 will work just fine. SamplesThere are some WMIC samples available on this site:
Except for CheckRegAccess.bat, PausePrinting.bat, ResumePrinting.bat, Printing.bat, and the reboot and shutdown, these samples are all limited to Get (read) property values only. More samples (be careful, some of these do actually change your system configuration): More to explore:A good source for more information is the article WMIC - Take Command-line Control over WMI by Ethan Wilansky. Examples of WMIC commands for Windows .NET SERVER Family Using Windows Management Instrumentation Command-line And Alain Lissoir's book: Understanding WMI Scriptingwhich devotes an entire chapter to WMIC. Microsoft Windows 2000 Scripting Guideprovides an excellent explanation of WQL use in its chapter Retrieving Managed Resources Using WMI Query Language. Is WMIC is the commandWMIC is the command-line version of WMI that can be used in batch scripting.
What is WMIC in batch file?Windows Management Instrumentation Command line (WMIC)
WMIC operates in two modes, interactive (which allows commands to be entered one line at a time) and non-interactive (which allows commands to be scripted for use in batch files). The simplest way to launch WMIC is to open a Run dialog and type wmic.
What is WMI and WMIC?What is WMIC? The Windows Management Instrumentation (WMI) Command-Line Utility (WMIC) is a command-line utility that allows users to perform WMI operations from a command prompt. WMI is an interface providing a variety of Windows management functions.
What does WMIC mean?A Description of the Windows Management Instrumentation (WMI) Command-Line Utility (Wmic.exe) - Microsoft Support.
|