Win32_Service, ROOT\cimv2, VBScript samples

Class | Childs (1) | Methods (12) | Properties (25) | Qualifiers (7) | Instances (80) | Namespaces (4)
Samples: VB Script | C# | VB.Net | Search on:Microsoft

Win32_Service - VB Script code samples

Get instance of WMI class using GetObject, AcceptPause property of Win32_Service

Short VBS code - get a single specified instance of Win32_Service class or get a default unnamed instance (singleton) of the class, using one single command GetObject with exact path of the wmi object.
	
	'https://wutils.com/wmi/
	Dim wmiObject
	Set wmiObject = GetObject( _
	 "WINMGMTS:\\.\ROOT\cimv2:" + _
	 "Win32_Service.Name=""adfssrv""")
	Wscript.Echo wmiObject.AcceptPause 'or other property name, see properties
	

Alternative codes

SWbemServices.Get

Quickest and most efficient VB Script code to get a single instance by a key - SWbemServices.Get
	'https://wutils.com/wmi/
	Dim oWMI, Instance
	
	'Get base WMI object, "." means computer name (local)
	Set oWMI = GetObject("WINMGMTS:\\.\ROOT\cimv2")
	
	Do
	  'Get the instance of Win32_Service 
	  Set Instance = oWMI.Get("Win32_Service.Name=""adfssrv""")
	                    
	  'Do something with the instance
	  Wscript.Echo Instance.AcceptPause 'or other property name, see properties
	
	  'Wait for some time to get next value
	  Wscript.Sleep 1000
	Loop While True  
	  
	

WMI query - sample windows WQL

Get a specified instance of Win32_Service by a key, get a default unnamed instance (singleton) of the class or list instances of the class by wmi query using this VB Script.
See in another language: C#, VB.Net.
	'https://wutils.com/wmi/
	Dim oWMI, WQL, Instances, Instance
	
	'Get base WMI object, "." means computer name (local)
	Set oWMI = GetObject("WINMGMTS:\\.\ROOT\cimv2")
	
	'Create a WMI query text 
	WQL = "Select * from Win32_Service Where Name=""adfssrv"""
	
	'Get instances of Win32_Service 
	Set Instances = oWMI.ExecQuery(WQL)
	                    
	'Enumerate instances  
	For Each Instance In Instances 
	  'Do something with the instance
	  Wscript.Echo Instance.AcceptPause 'or other property name
	Next 'Instance
	

InstancesOf

List of all instances, wmi class Win32_Service.
	'https://wutils.com/wmi/
	Dim oWMI, Instances, Instance
	
	'Get base WMI object, "." means computer name (local)
	Set oWMI = GetObject("WINMGMTS:\\.\ROOT\cimv2")
	
	'Get instances of Win32_Service - all instances of this class and derived classes 
	'Set Instances = oWMI.InstancesOf("Win32_Service")
	
	'Get instances of Win32_Service 
	Set Instances = oWMI.InstancesOf("Win32_Service", 1)
	
	
	'Enumerate instances  
	For Each Instance In Instances 
	  'Do something with the instance
	  Wscript.Echo Instance.AcceptPause 'or other property name
	Next 'Instance
	

WMI remote scripting - Locator, Connect

Get WMI management object using SWbemLocator.ConnectServer method. You can connect to a remote computer and specify Username/Password for the WMI connection.
	'https://wutils.com/wmi/
	Dim Locator, oWMI, WQL, Instances, Instance
	
	'Create Locator object
	Set Locator = CreateObject("WbemScripting.SWbemLocator")
	
	'Get base WMI object
	Set oWMI = Locator.ConnectServer("MachineName", "ROOT\cimv2", "MachineName\administrator", "Password")
	 
	'.... continue using oWMI object
	
	
comments powered by Disqus
online utility - toplist
WUtils.com