You can download the scripting program for generating these scripts at:
http://www.planetmps.com/wmiscriptsENQ_O.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="vbscript">
<![CDATA[
Dim l
Dim svc
Dim ob
Dim objs
Dim obj
Dim prop
Dim tstr
Set l = CreateObject("WbemScripting.SWbemLocator")
Set svc = l.ConnectServer(".", "root\cimv2")
Set objs = svc.ExecNotificationQuery("Select * From __InstanceOperationEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
For each obj in objs
For each prop in obj.Properties_
tstr = tstr & prop.Name & " = " & GetValue(prop.Name, obj) & vbcrlf
Next
WScript.Echo(tstr)
tstr = ""
Next
function GetValue(Name, obj)
Dim tempstr
Dim pname
Dim pos
pname = Name & " = "
pos = InStr(obj.GetObjectText_, pname)
If pos Then
pos = pos + Len(pname)
tempstr = Mid(obj.GetObjectText_, pos, Len(obj.GetObjectText_))
pos = InStr(tempstr, ";")
tempstr = Mid(tempstr, 1, pos - 1)
tempstr = Replace(tempstr, Chr(34), "")
tempstr = Replace(tempstr, "{", "")
tempstr = Replace(tempstr, "}", "")
If (obj.Properties_(Name).CIMtype = 101 And Len(tempstr) > 14) Then
GetValue = Mid(tempstr, 5, 2) + "/" + _
Mid(tempstr, 7, 2) + "/" + _
Mid(tempstr, 1, 4) + " " + _
Mid(tempstr, 9, 2) + ":" + _
Mid(tempstr, 11, 2) + ":" + _
Mid(tempstr, 13, 2)
Else
GetValue = tempstr
End If
Else
GetValue = ""
End If
End Function
]]>
</script>
</job>
</package>
WMI Coding Examples
Wednesday, July 6, 2011
WSH VBScript WMI Example using ExecNotificationQuery with __InstanceCreationEvent
You can download the scripting program for generating these scripts at:
http://www.planetmps.com/wmiscriptsENQ_C.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="vbscript">
<![CDATA[
Dim l
Dim svc
Dim ob
Dim objs
Dim obj
Dim prop
Dim tstr
Set l = CreateObject("WbemScripting.SWbemLocator")
Set svc = l.ConnectServer(".", "root\cimv2")
Set objs = svc.ExecNotificationQuery("Select * From __InstanceCreationEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
For each obj in objs
For each prop in obj.Properties_
tstr = tstr & prop.Name & " = " & GetValue(prop.Name, obj) & vbcrlf
Next
WScript.Echo(tstr)
tstr = ""
Next
function GetValue(Name, obj)
Dim tempstr
Dim pname
Dim pos
pname = Name & " = "
pos = InStr(obj.GetObjectText_, pname)
If pos Then
pos = pos + Len(pname)
tempstr = Mid(obj.GetObjectText_, pos, Len(obj.GetObjectText_))
pos = InStr(tempstr, ";")
tempstr = Mid(tempstr, 1, pos - 1)
tempstr = Replace(tempstr, Chr(34), "")
tempstr = Replace(tempstr, "{", "")
tempstr = Replace(tempstr, "}", "")
If (obj.Properties_(Name).CIMtype = 101 And Len(tempstr) > 14) Then
GetValue = Mid(tempstr, 5, 2) + "/" + _
Mid(tempstr, 7, 2) + "/" + _
Mid(tempstr, 1, 4) + " " + _
Mid(tempstr, 9, 2) + ":" + _
Mid(tempstr, 11, 2) + ":" + _
Mid(tempstr, 13, 2)
Else
GetValue = tempstr
End If
Else
GetValue = ""
End If
End Function
]]>
</script>
</job>
</package>
http://www.planetmps.com/wmiscriptsENQ_C.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="vbscript">
<![CDATA[
Dim l
Dim svc
Dim ob
Dim objs
Dim obj
Dim prop
Dim tstr
Set l = CreateObject("WbemScripting.SWbemLocator")
Set svc = l.ConnectServer(".", "root\cimv2")
Set objs = svc.ExecNotificationQuery("Select * From __InstanceCreationEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
For each obj in objs
For each prop in obj.Properties_
tstr = tstr & prop.Name & " = " & GetValue(prop.Name, obj) & vbcrlf
Next
WScript.Echo(tstr)
tstr = ""
Next
function GetValue(Name, obj)
Dim tempstr
Dim pname
Dim pos
pname = Name & " = "
pos = InStr(obj.GetObjectText_, pname)
If pos Then
pos = pos + Len(pname)
tempstr = Mid(obj.GetObjectText_, pos, Len(obj.GetObjectText_))
pos = InStr(tempstr, ";")
tempstr = Mid(tempstr, 1, pos - 1)
tempstr = Replace(tempstr, Chr(34), "")
tempstr = Replace(tempstr, "{", "")
tempstr = Replace(tempstr, "}", "")
If (obj.Properties_(Name).CIMtype = 101 And Len(tempstr) > 14) Then
GetValue = Mid(tempstr, 5, 2) + "/" + _
Mid(tempstr, 7, 2) + "/" + _
Mid(tempstr, 1, 4) + " " + _
Mid(tempstr, 9, 2) + ":" + _
Mid(tempstr, 11, 2) + ":" + _
Mid(tempstr, 13, 2)
Else
GetValue = tempstr
End If
Else
GetValue = ""
End If
End Function
]]>
</script>
</job>
</package>
WSH VBScript WMI Example using ExecNotificationQuery with __InstanceModificationEvent
You can download the scripting program for generating these scripts at:
http://www.planetmps.com/wmiscriptsENQ_M.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="vbscript">
<![CDATA[
Dim l
Dim svc
Dim ob
Dim objs
Dim obj
Dim prop
Dim tstr
Set l = CreateObject("WbemScripting.SWbemLocator")
Set svc = l.ConnectServer(".", "root\cimv2")
Set objs = svc.ExecNotificationQuery("Select * From __InstanceModificationEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
For each obj in objs
For each prop in obj.Properties_
tstr = tstr & prop.Name & " = " & GetValue(prop.Name, obj) & vbcrlf
Next
WScript.Echo(tstr)
tstr = ""
Next
function GetValue(Name, obj)
Dim tempstr
Dim pname
Dim pos
pname = Name & " = "
pos = InStr(obj.GetObjectText_, pname)
If pos Then
pos = pos + Len(pname)
tempstr = Mid(obj.GetObjectText_, pos, Len(obj.GetObjectText_))
pos = InStr(tempstr, ";")
tempstr = Mid(tempstr, 1, pos - 1)
tempstr = Replace(tempstr, Chr(34), "")
tempstr = Replace(tempstr, "{", "")
tempstr = Replace(tempstr, "}", "")
If (obj.Properties_(Name).CIMtype = 101 And Len(tempstr) > 14) Then
GetValue = Mid(tempstr, 5, 2) + "/" + _
Mid(tempstr, 7, 2) + "/" + _
Mid(tempstr, 1, 4) + " " + _
Mid(tempstr, 9, 2) + ":" + _
Mid(tempstr, 11, 2) + ":" + _
Mid(tempstr, 13, 2)
Else
GetValue = tempstr
End If
Else
GetValue = ""
End If
End Function
]]>
</script>
</job>
</package>
http://www.planetmps.com/wmiscriptsENQ_M.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="vbscript">
<![CDATA[
Dim l
Dim svc
Dim ob
Dim objs
Dim obj
Dim prop
Dim tstr
Set l = CreateObject("WbemScripting.SWbemLocator")
Set svc = l.ConnectServer(".", "root\cimv2")
Set objs = svc.ExecNotificationQuery("Select * From __InstanceModificationEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
For each obj in objs
For each prop in obj.Properties_
tstr = tstr & prop.Name & " = " & GetValue(prop.Name, obj) & vbcrlf
Next
WScript.Echo(tstr)
tstr = ""
Next
function GetValue(Name, obj)
Dim tempstr
Dim pname
Dim pos
pname = Name & " = "
pos = InStr(obj.GetObjectText_, pname)
If pos Then
pos = pos + Len(pname)
tempstr = Mid(obj.GetObjectText_, pos, Len(obj.GetObjectText_))
pos = InStr(tempstr, ";")
tempstr = Mid(tempstr, 1, pos - 1)
tempstr = Replace(tempstr, Chr(34), "")
tempstr = Replace(tempstr, "{", "")
tempstr = Replace(tempstr, "}", "")
If (obj.Properties_(Name).CIMtype = 101 And Len(tempstr) > 14) Then
GetValue = Mid(tempstr, 5, 2) + "/" + _
Mid(tempstr, 7, 2) + "/" + _
Mid(tempstr, 1, 4) + " " + _
Mid(tempstr, 9, 2) + ":" + _
Mid(tempstr, 11, 2) + ":" + _
Mid(tempstr, 13, 2)
Else
GetValue = tempstr
End If
Else
GetValue = ""
End If
End Function
]]>
</script>
</job>
</package>
WSH VBScript WMI Example using ExecNotificationQuery with __InstanceDeletionEvent
You can download the scripting program for generating these scripts at:
http://www.planetmps.com/wmiscriptsENQ_D.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="vbscript">
<![CDATA[
Dim l
Dim svc
Dim ob
Dim objs
Dim obj
Dim prop
Dim tstr
Set l = CreateObject("WbemScripting.SWbemLocator")
Set svc = l.ConnectServer(".", "root\cimv2")
Set objs = svc.ExecNotificationQuery("Select * From __InstanceDeletionEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
For each obj in objs
For each prop in obj.Properties_
tstr = tstr & prop.Name & " = " & GetValue(prop.Name, obj) & vbcrlf
Next
WScript.Echo(tstr)
tstr = ""
Next
function GetValue(Name, obj)
Dim tempstr
Dim pname
Dim pos
pname = Name & " = "
pos = InStr(obj.GetObjectText_, pname)
If pos Then
pos = pos + Len(pname)
tempstr = Mid(obj.GetObjectText_, pos, Len(obj.GetObjectText_))
pos = InStr(tempstr, ";")
tempstr = Mid(tempstr, 1, pos - 1)
tempstr = Replace(tempstr, Chr(34), "")
tempstr = Replace(tempstr, "{", "")
tempstr = Replace(tempstr, "}", "")
If (obj.Properties_(Name).CIMtype = 101 And Len(tempstr) > 14) Then
GetValue = Mid(tempstr, 5, 2) + "/" + _
Mid(tempstr, 7, 2) + "/" + _
Mid(tempstr, 1, 4) + " " + _
Mid(tempstr, 9, 2) + ":" + _
Mid(tempstr, 11, 2) + ":" + _
Mid(tempstr, 13, 2)
Else
GetValue = tempstr
End If
Else
GetValue = ""
End If
End Function
]]>
</script>
</job>
</package>
http://www.planetmps.com/wmiscriptsENQ_D.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="vbscript">
<![CDATA[
Dim l
Dim svc
Dim ob
Dim objs
Dim obj
Dim prop
Dim tstr
Set l = CreateObject("WbemScripting.SWbemLocator")
Set svc = l.ConnectServer(".", "root\cimv2")
Set objs = svc.ExecNotificationQuery("Select * From __InstanceDeletionEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
For each obj in objs
For each prop in obj.Properties_
tstr = tstr & prop.Name & " = " & GetValue(prop.Name, obj) & vbcrlf
Next
WScript.Echo(tstr)
tstr = ""
Next
function GetValue(Name, obj)
Dim tempstr
Dim pname
Dim pos
pname = Name & " = "
pos = InStr(obj.GetObjectText_, pname)
If pos Then
pos = pos + Len(pname)
tempstr = Mid(obj.GetObjectText_, pos, Len(obj.GetObjectText_))
pos = InStr(tempstr, ";")
tempstr = Mid(tempstr, 1, pos - 1)
tempstr = Replace(tempstr, Chr(34), "")
tempstr = Replace(tempstr, "{", "")
tempstr = Replace(tempstr, "}", "")
If (obj.Properties_(Name).CIMtype = 101 And Len(tempstr) > 14) Then
GetValue = Mid(tempstr, 5, 2) + "/" + _
Mid(tempstr, 7, 2) + "/" + _
Mid(tempstr, 1, 4) + " " + _
Mid(tempstr, 9, 2) + ":" + _
Mid(tempstr, 11, 2) + ":" + _
Mid(tempstr, 13, 2)
Else
GetValue = tempstr
End If
Else
GetValue = ""
End If
End Function
]]>
</script>
</job>
</package>
WSH VBScript WMI Example using ExecNotificationQuery with __InstanceCreationEvent
You can download the scripting program for generating these scripts at:
http://www.planetmps.com/wmiscriptsENQ_C.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="vbscript">
<![CDATA[
Dim l
Dim svc
Dim ob
Dim objs
Dim obj
Dim prop
Dim tstr
Set l = CreateObject("WbemScripting.SWbemLocator")
Set svc = l.ConnectServer(".", "root\cimv2")
Set objs = svc.ExecNotificationQuery("Select * From __InstanceCreationEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
For each obj in objs
For each prop in obj.Properties_
tstr = tstr & prop.Name & " = " & GetValue(prop.Name, obj) & vbcrlf
Next
WScript.Echo(tstr)
tstr = ""
Next
function GetValue(Name, obj)
Dim tempstr
Dim pname
Dim pos
pname = Name & " = "
pos = InStr(obj.GetObjectText_, pname)
If pos Then
pos = pos + Len(pname)
tempstr = Mid(obj.GetObjectText_, pos, Len(obj.GetObjectText_))
pos = InStr(tempstr, ";")
tempstr = Mid(tempstr, 1, pos - 1)
tempstr = Replace(tempstr, Chr(34), "")
tempstr = Replace(tempstr, "{", "")
tempstr = Replace(tempstr, "}", "")
If (obj.Properties_(Name).CIMtype = 101 And Len(tempstr) > 14) Then
GetValue = Mid(tempstr, 5, 2) + "/" + _
Mid(tempstr, 7, 2) + "/" + _
Mid(tempstr, 1, 4) + " " + _
Mid(tempstr, 9, 2) + ":" + _
Mid(tempstr, 11, 2) + ":" + _
Mid(tempstr, 13, 2)
Else
GetValue = tempstr
End If
Else
GetValue = ""
End If
End Function
]]>
</script>
</job>
</package>
http://www.planetmps.com/wmiscriptsENQ_C.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="vbscript">
<![CDATA[
Dim l
Dim svc
Dim ob
Dim objs
Dim obj
Dim prop
Dim tstr
Set l = CreateObject("WbemScripting.SWbemLocator")
Set svc = l.ConnectServer(".", "root\cimv2")
Set objs = svc.ExecNotificationQuery("Select * From __InstanceCreationEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
For each obj in objs
For each prop in obj.Properties_
tstr = tstr & prop.Name & " = " & GetValue(prop.Name, obj) & vbcrlf
Next
WScript.Echo(tstr)
tstr = ""
Next
function GetValue(Name, obj)
Dim tempstr
Dim pname
Dim pos
pname = Name & " = "
pos = InStr(obj.GetObjectText_, pname)
If pos Then
pos = pos + Len(pname)
tempstr = Mid(obj.GetObjectText_, pos, Len(obj.GetObjectText_))
pos = InStr(tempstr, ";")
tempstr = Mid(tempstr, 1, pos - 1)
tempstr = Replace(tempstr, Chr(34), "")
tempstr = Replace(tempstr, "{", "")
tempstr = Replace(tempstr, "}", "")
If (obj.Properties_(Name).CIMtype = 101 And Len(tempstr) > 14) Then
GetValue = Mid(tempstr, 5, 2) + "/" + _
Mid(tempstr, 7, 2) + "/" + _
Mid(tempstr, 1, 4) + " " + _
Mid(tempstr, 9, 2) + ":" + _
Mid(tempstr, 11, 2) + ":" + _
Mid(tempstr, 13, 2)
Else
GetValue = tempstr
End If
Else
GetValue = ""
End If
End Function
]]>
</script>
</job>
</package>
WSH VBScript WMI Example using ExecQuery
You can download the scripting program for generating these scripts at:
http://www.planetmps.com/wmiscriptsexecquery.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="vbscript">
<![CDATA[
Dim l
Dim svc
Dim ob
Dim objs
Dim obj
Dim prop
Dim tstr
Set l = CreateObject("WbemScripting.SWbemLocator")
Set svc = l.ConnectServer(".", "root\cimv2")
Set objs = svc.ExecQuery("Select * From Win32_Process")
For each obj in objs
For each prop in obj.Properties_
tstr = tstr & prop.Name & " = " & GetValue(prop.Name, obj) & vbcrlf
Next
WScript.Echo(tstr)
tstr = ""
Next
function GetValue(Name, obj)
Dim tempstr
Dim pname
Dim pos
pname = Name & " = "
pos = InStr(obj.GetObjectText_, pname)
If pos Then
pos = pos + Len(pname)
tempstr = Mid(obj.GetObjectText_, pos, Len(obj.GetObjectText_))
pos = InStr(tempstr, ";")
tempstr = Mid(tempstr, 1, pos - 1)
tempstr = Replace(tempstr, Chr(34), "")
tempstr = Replace(tempstr, "{", "")
tempstr = Replace(tempstr, "}", "")
If (obj.Properties_(Name).CIMtype = 101 And Len(tempstr) > 14) Then
GetValue = Mid(tempstr, 5, 2) + "/" + _
Mid(tempstr, 7, 2) + "/" + _
Mid(tempstr, 1, 4) + " " + _
Mid(tempstr, 9, 2) + ":" + _
Mid(tempstr, 11, 2) + ":" + _
Mid(tempstr, 13, 2)
Else
GetValue = tempstr
End If
Else
GetValue = ""
End If
End Function
]]>
</script>
</job>
</package>
http://www.planetmps.com/wmiscriptsexecquery.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="vbscript">
<![CDATA[
Dim l
Dim svc
Dim ob
Dim objs
Dim obj
Dim prop
Dim tstr
Set l = CreateObject("WbemScripting.SWbemLocator")
Set svc = l.ConnectServer(".", "root\cimv2")
Set objs = svc.ExecQuery("Select * From Win32_Process")
For each obj in objs
For each prop in obj.Properties_
tstr = tstr & prop.Name & " = " & GetValue(prop.Name, obj) & vbcrlf
Next
WScript.Echo(tstr)
tstr = ""
Next
function GetValue(Name, obj)
Dim tempstr
Dim pname
Dim pos
pname = Name & " = "
pos = InStr(obj.GetObjectText_, pname)
If pos Then
pos = pos + Len(pname)
tempstr = Mid(obj.GetObjectText_, pos, Len(obj.GetObjectText_))
pos = InStr(tempstr, ";")
tempstr = Mid(tempstr, 1, pos - 1)
tempstr = Replace(tempstr, Chr(34), "")
tempstr = Replace(tempstr, "{", "")
tempstr = Replace(tempstr, "}", "")
If (obj.Properties_(Name).CIMtype = 101 And Len(tempstr) > 14) Then
GetValue = Mid(tempstr, 5, 2) + "/" + _
Mid(tempstr, 7, 2) + "/" + _
Mid(tempstr, 1, 4) + " " + _
Mid(tempstr, 9, 2) + ":" + _
Mid(tempstr, 11, 2) + ":" + _
Mid(tempstr, 13, 2)
Else
GetValue = tempstr
End If
Else
GetValue = ""
End If
End Function
]]>
</script>
</job>
</package>
WSH VBScript WMI Example Using Instancesof
You can download the scripting program for generating these scripts at:
http://www.planetmps.com/wmiscriptsinstancesof.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="vbscript">
<![CDATA[
Dim l
Dim svc
Dim ob
Dim objs
Dim obj
Dim prop
Dim tstr
Set l = CreateObject("WbemScripting.SWbemLocator")
Set svc = l.ConnectServer(".", "root\cimv2")
Set objs = svc.InstancesOf("Win32_Process")
For each obj in objs
For each prop in obj.Properties_
tstr = tstr & prop.Name & " = " & GetValue(prop.Name, obj) & vbcrlf
Next
WScript.Echo(tstr)
tstr = ""
Next
function GetValue(Name, obj)
Dim tempstr
Dim pname
Dim pos
pname = Name & " = "
pos = InStr(obj.GetObjectText_, pname)
If pos Then
pos = pos + Len(pname)
tempstr = Mid(obj.GetObjectText_, pos, Len(obj.GetObjectText_))
pos = InStr(tempstr, ";")
tempstr = Mid(tempstr, 1, pos - 1)
tempstr = Replace(tempstr, Chr(34), "")
tempstr = Replace(tempstr, "{", "")
tempstr = Replace(tempstr, "}", "")
If (obj.Properties_(Name).CIMtype = 101 And Len(tempstr) > 14) Then
GetValue = Mid(tempstr, 5, 2) + "/" + _
Mid(tempstr, 7, 2) + "/" + _
Mid(tempstr, 1, 4) + " " + _
Mid(tempstr, 9, 2) + ":" + _
Mid(tempstr, 11, 2) + ":" + _
Mid(tempstr, 13, 2)
Else
GetValue = tempstr
End If
Else
GetValue = ""
End If
End Function
]]>
</script>
</job>
</package>
http://www.planetmps.com/wmiscriptsinstancesof.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="vbscript">
<![CDATA[
Dim l
Dim svc
Dim ob
Dim objs
Dim obj
Dim prop
Dim tstr
Set l = CreateObject("WbemScripting.SWbemLocator")
Set svc = l.ConnectServer(".", "root\cimv2")
Set objs = svc.InstancesOf("Win32_Process")
For each obj in objs
For each prop in obj.Properties_
tstr = tstr & prop.Name & " = " & GetValue(prop.Name, obj) & vbcrlf
Next
WScript.Echo(tstr)
tstr = ""
Next
function GetValue(Name, obj)
Dim tempstr
Dim pname
Dim pos
pname = Name & " = "
pos = InStr(obj.GetObjectText_, pname)
If pos Then
pos = pos + Len(pname)
tempstr = Mid(obj.GetObjectText_, pos, Len(obj.GetObjectText_))
pos = InStr(tempstr, ";")
tempstr = Mid(tempstr, 1, pos - 1)
tempstr = Replace(tempstr, Chr(34), "")
tempstr = Replace(tempstr, "{", "")
tempstr = Replace(tempstr, "}", "")
If (obj.Properties_(Name).CIMtype = 101 And Len(tempstr) > 14) Then
GetValue = Mid(tempstr, 5, 2) + "/" + _
Mid(tempstr, 7, 2) + "/" + _
Mid(tempstr, 1, 4) + " " + _
Mid(tempstr, 9, 2) + ":" + _
Mid(tempstr, 11, 2) + ":" + _
Mid(tempstr, 13, 2)
Else
GetValue = tempstr
End If
Else
GetValue = ""
End If
End Function
]]>
</script>
</job>
</package>
Subscribe to:
Posts (Atom)