Skip to main content

WMIC

WMIC is a command line interface to WMI (Windows Management Instrumentation). WMI is a powerful management interface that we can access from directly from command line. 

WMIC can be used to manage remote computers. 
If we want to execute WMIC commands on a single computer we prepend command with /node: as shown below:

/node:hostname123 - specifies single server 
(wmic /node:hostname123 qfe where hotfixid="KB974571" list full)

If we want to execute WMIC commands on multiple computers listed in c:\nodes.txt we prepend command with /node:@ as shown below:


/node:@'c:\node.txt' - specifies text file with server names 
 (wmic /node:@'c:\node.txt' qfe where hotfixid="KB974571" list full)

It's worth keeping in mind that not all WMI classes have corresponding classes (called aliases) in WMIC. It is however possible to access WMI classes directly from WMIC:

wmic /namespace:\\root\NAMSPACE path CLASSNAME

To directly access WMI classes in CIMv2 namespace  

wmic /namespace:\\root\cimv2 path win32_useraccount


To see if there are any predictive failures using WMIC: 

wmic /namespace:\\root\wmi PATH MSStorageDriver_FailurePredictStatus get 

We can use Microsoft WMI Studio to explorer WMI classes, properties and methods


We can tell WMIC to repeat a command at specified interval:

/every:5    -  repeats a command every 5 seconds 

WMIC can also output to an HTML file using /output and /format switches 

wmic /output:c:\cpu.htm cpu get name, maxclockspeed /format:hform.xsl

HTML output is no longer available in Windows 2008 or 7, on these platforms we omit /format switch.




qfe - wmic query for hotfixes and patches 

query for a given patch by using a KB ID: 

wmic qfe where hotfixid="KB974571" list full


process - process management 

query for an exe path of a process 

wmic process where caption="Apntex.exe" get executablepath  

query for a process's thread count  

wmic process where caption="Apntex.exe" get threadcount 

to execute a  command on a remote machine  

wmic /node:hostname process call create 'cmd.exe /c net stop iisadmin' 

To kill a process using WMIC: 

wmic process where caption="notepad.exe" call terminate 


service - service management: 

Disable service using WMIC

wmic service where caption='SSDP Discovery Service' call changestartmode disabled 

Enable service using WMIC

wmic service where caption='SSDP Discovery Service'  call changestartmode enabled 

Stop service using WMIC

wmic service where caption='SSDP Discovery Service'  call stopservice 

Startservice using WMIC

wmic service where caption='SSDP Discovery Service' call startservice 

Retrieve service status

wmic service where name='........'  get status 

To retrieve service name: 

wmic service list instance 


product - Software Management 

List installed software: 

wmic product get

wmic product list brief 
  
Only required attributes: 

wmic product get name, vendor, version 

Only products from Adobe: 

wmic product where "vendor like 'adobe%'" get 

  
 Find out a username of a user logged on to a computer: 

wmic /NODE:hostname COMPUTERSYSTEM GET USERNAME 

 Configure a static IP address using WMIC: 

wmic nicconfig where Index=1 call EnableStatic ("10.10.10.10"), ("255.255.255.0") 

To retrieve index ID: 

wmi nicconfig where ipenabled='true' 
  
Enable DHCP using WMIC: 

wmic nicconfig where Index=1 call EnableDHCP


File management using WMIC: 

list details about c:\script\comps.txt file 

wmic datafile where "path='\\scripts\\' and name='c:\\scripts\\comps.txt'" list full   

Backup event log using WMIC:

wmic nteventlog where "logfilename='system'" call backupeventlog "c:\system.evt"

wmic nteventlog where "logfilename='application'" call backupeventlog "c:\application.evt"


Query local groups:

wmic group where (localaccount=true) get name

Local groups with "sql" in the name:


wmic group where (localaccount=true and name like 'sql%') get name

Comments

Popular posts from this blog

x.509 Certificates - Critical vs non-critical extensions

Extensions are used to associate additional information with the user or the key.  Each certificate extension has three attributes - extnID, critical, extnValue extnID - Extension ID - an OID that specifies the format and definitions of the extension critical - Critical flag - Boolean value extnValue - Extension value  Criticality flag specifies whether the information in an extension is important. If an application doesn't recognize the extension marked as critical, the certificate cannot be accepted. If an extension is not marked as critical (critical value False) it can be ignored by an application. In Windows, critical extensions are marked with a yellow exclamation mark,  View certificate extensions using OpenSSL: # openssl x509 -inform pem -in cert.pem -text -noout (output abbreviated)         X509v3 extensions:             X509v3 Key Usage: critical          ...

DNS response and error types

In this post we explore common DNS response codes. We will cover the following responses: NOERROR SERVFAIL NXDOMAIN NODATA REFUSED Throughout article we’ll refer to the following RFCs: RFC 1034 - DOMAIN NAMES - CONCEPTS AND FACILITIES RFC 2308 - Negative Caching of DNS Queries (DNS NCACHE) RFC 2136 - Dynamic Updates in the Domain Name System (DNS UPDATE) RFC 8914 - Extended DNS Errors Response Codes - RCODEs The DNS RCODES are best defined in RFC2316 .  They signify what type of response was sent by the server. “RCODE   Response code - this four bit field is undefined in requests and set in responses.”   The table below shows the summary of the currently defined RCODEs. Mnemonic Val Description NOERROR 0 No error condition. ...

DNS blocking in Indonesia

DNS based censorship and domain blocking in Indonesia is very inconsistent among ISPs. There’s a government mandated black list which the ISPs operating in the country should enforce. However, Indonesia lacks centralised internet infrastructure and has many separate ISPs. In addition, the Indonesian government granted ISPs the authority to block content at their own discretion. All of this leads to a very inconsistent DNS blocking in Indonesia. Official DNS domain blacklist in Indonesia The Government mandated DNS blacklist is published in a redacted form and can be downloaded here: https://trustpositif.kominfo.go.id/ . This is where the blocked domains get redirected to. We can search the database and check if a domain is blocked. In the screenshot below we can see that a popular cryptocurrency exchange is blocked (Ada) and that wikipedia.org is not (Tidak Ada) - thanks to Google Translate. Examples of blocked DNS queries dig binance.com @182.253.45.122 ;; global options: +cmd ;; Got ...