WMI

Purpose
Windows Management Instrumentation (WMI) is the infrastructure for management data and operations on Windows-based operating
systems. we can write WMI scripts or applications to automate administrative tasks on remote computers and WMI also supplies
management data to other parts of the operating system and products.

Starting WMI Service
WMI runs as a service with the display name "Windows Management Instrumentation" and the service name "winmgmt". WMI runs
automatically at system startup under the LocalSystem account. If WMI is not running, it automatically starts when the first
management application or script requests connection to a WMI namespace.
======================================================
''''''Display the list of namespaces in WMI service
======================================================
strComputer = "."
Set ms = GetObject("winmgmts:\\" & strComputer & "\root")
Set ns=ms.InstancesOf("__NAMESPACE")
For Each n In ns
print n.Name
Next
================================================='
''Display the list of classes in cimv2 names space
=================================================
strComputer = "."
Set ms =GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set clss = ms.SubclassesOf()
For Each c In clss
print c.Path_.PathNext
================================================
The Win32_Process class defines the following methods.
AttachDebugger : Launches the currently registered debugger for a process.
Create : Creates a new process.
GetOwner : Retrieves the user name and domain name under which the process is running.
GetOwnerSid : Retrieves the security identifier (SID) for the owner of a process.
SetPriority : Changes the execution priority of a process.
Terminate : Terminates a process and all of its threads.
=============================================
''''''''Create a notepad application
=============================================
strComputer = "."
Set ms = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set p = ms.get("Win32_Process")
p.create "notepad.exe"
=============================================
'''''''Terminate all the instances of notepad.exe running in the system
=============================================
strComputer = "."
Set wms =GetObject("winmgmts:\\" & strComputer&"\root\cimv2")
Set citems=wms.ExecQuery("Select * from Win32_process where Name='notepad.exe' ")
For each p in citems
p.Terminate
Next
==============================================
The Win32_product class defines the following methods.
Install :
Installs an associated Win32_Product instance using the installation package provided through PackageLocation and
any command line options that are supplied.
Admin : Performs an administrative install of an associated Win32_Product instance using the installation package provided
through PackageLocation, and any command line options that are supplied.
Advertise : Advertises an associated Win32_Product instance using the installation package provided through PackageLocation
and any command line options that are supplied.
Reinstall : Reinstalls the associated instance of Win32_Product using the specified reinstallation mode.
Upgrade : Upgrades the associated Win32_Product instance using the upgrade package provided through PackageLocation and any
command line options that are supplied.
Configure : Configures the associated instance of Win32_Product to the specified install state and level.
Uninstall : Uninstalls the associated instance of Win32_Product.

Comments