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>
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>
WSH VBScript WMI Example Using Instances
You can download the scripting program for generating these scripts at:
http://www.planetmps.com/wmiscriptsinstances.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 ob = svc.Get("Win32_Process")
Set objs = ob.Instances_
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/wmiscriptsinstances.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 ob = svc.Get("Win32_Process")
Set objs = ob.Instances_
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 Ruby WMI Example Using ExecNotificationQuery With __InstanceOperationEvent
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="ruby">
<![CDATA[
require("win32ole")
i=0
locator = WIN32OLE.new("WbemScripting.SWbemLocator")
svc = locator.connectserver()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.ExecNotificationQuery("Select * From __InstanceOperationEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
mystr = ""
objs.each{ |obj|
obj.Properties_.each{ |prop|
End
End
]]>
</script>
</job>
</package>
http://www.planetmps.com/wmiscriptsENQ_O.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="ruby">
<![CDATA[
require("win32ole")
i=0
locator = WIN32OLE.new("WbemScripting.SWbemLocator")
svc = locator.connectserver()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.ExecNotificationQuery("Select * From __InstanceOperationEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
mystr = ""
objs.each{ |obj|
obj.Properties_.each{ |prop|
End
End
]]>
</script>
</job>
</package>
WSH Ruby 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="ruby">
<![CDATA[
require("win32ole")
i=0
locator = WIN32OLE.new("WbemScripting.SWbemLocator")
svc = locator.connectserver()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.ExecNotificationQuery("Select * From __InstanceModificationEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
mystr = ""
objs.each{ |obj|
obj.Properties_.each{ |prop|
End
End
]]>
</script>
</job>
</package>
http://www.planetmps.com/wmiscriptsENQ_M.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="ruby">
<![CDATA[
require("win32ole")
i=0
locator = WIN32OLE.new("WbemScripting.SWbemLocator")
svc = locator.connectserver()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.ExecNotificationQuery("Select * From __InstanceModificationEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
mystr = ""
objs.each{ |obj|
obj.Properties_.each{ |prop|
End
End
]]>
</script>
</job>
</package>
WSH Ruby 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="ruby">
<![CDATA[
require("win32ole")
i=0
locator = WIN32OLE.new("WbemScripting.SWbemLocator")
svc = locator.connectserver()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.ExecNotificationQuery("Select * From __InstanceDeletionEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
mystr = ""
objs.each{ |obj|
obj.Properties_.each{ |prop|
End
End
]]>
</script>
</job>
</package>
http://www.planetmps.com/wmiscriptsENQ_D.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="ruby">
<![CDATA[
require("win32ole")
i=0
locator = WIN32OLE.new("WbemScripting.SWbemLocator")
svc = locator.connectserver()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.ExecNotificationQuery("Select * From __InstanceDeletionEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
mystr = ""
objs.each{ |obj|
obj.Properties_.each{ |prop|
End
End
]]>
</script>
</job>
</package>
WSH Ruby 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="ruby">
<![CDATA[
require("win32ole")
i=0
locator = WIN32OLE.new("WbemScripting.SWbemLocator")
svc = locator.connectserver()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.ExecNotificationQuery("Select * From __InstanceCreationEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
mystr = ""
objs.each{ |obj|
obj.Properties_.each{ |prop|
End
End
]]>
</script>
</job>
</package>
http://www.planetmps.com/wmiscriptsENQ_C.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="ruby">
<![CDATA[
require("win32ole")
i=0
locator = WIN32OLE.new("WbemScripting.SWbemLocator")
svc = locator.connectserver()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.ExecNotificationQuery("Select * From __InstanceCreationEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
mystr = ""
objs.each{ |obj|
obj.Properties_.each{ |prop|
End
End
]]>
</script>
</job>
</package>
WSH Ruby 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="ruby">
<![CDATA[
require("win32ole")
i=0
locator = WIN32OLE.new("WbemScripting.SWbemLocator")
svc = locator.connectserver()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.ExecQuery("Select * From Win32_Process")
mystr = ""
objs.each{ |obj|
obj.Properties_.each{ |prop|
End
End
]]>
</script>
</job>
</package>
http://www.planetmps.com/wmiscriptsexecquery.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="ruby">
<![CDATA[
require("win32ole")
i=0
locator = WIN32OLE.new("WbemScripting.SWbemLocator")
svc = locator.connectserver()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.ExecQuery("Select * From Win32_Process")
mystr = ""
objs.each{ |obj|
obj.Properties_.each{ |prop|
End
End
]]>
</script>
</job>
</package>
WSH Ruby 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="ruby">
<![CDATA[
require("win32ole")
i=0
locator = WIN32OLE.new("WbemScripting.SWbemLocator")
svc = locator.connectserver()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.InstancesOf("Win32_Process")
mystr = ""
objs.each{ |obj|
obj.Properties_.each{ |prop|
End
End
]]>
</script>
</job>
</package>
http://www.planetmps.com/wmiscriptsinstancesof.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="ruby">
<![CDATA[
require("win32ole")
i=0
locator = WIN32OLE.new("WbemScripting.SWbemLocator")
svc = locator.connectserver()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.InstancesOf("Win32_Process")
mystr = ""
objs.each{ |obj|
obj.Properties_.each{ |prop|
End
End
]]>
</script>
</job>
</package>
WSH Ruby WMI Example Using Instances
You can download the scripting program for generating these scripts at:
http://www.planetmps.com/wmiscriptsinstances.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="ruby">
<![CDATA[
require("win32ole")
i=0
locator = WIN32OLE.new("WbemScripting.SWbemLocator")
svc = locator.connectserver()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
ob = svc.Get("Win32_Process")
objs = ob.Instances
mystr = ""
objs.each{ |obj|
obj.Properties_.each{ |prop|
End
End
]]>
</script>
</job>
</package>
http://www.planetmps.com/wmiscriptsinstances.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="ruby">
<![CDATA[
require("win32ole")
i=0
locator = WIN32OLE.new("WbemScripting.SWbemLocator")
svc = locator.connectserver()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
ob = svc.Get("Win32_Process")
objs = ob.Instances
mystr = ""
objs.each{ |obj|
obj.Properties_.each{ |prop|
End
End
]]>
</script>
</job>
</package>
WSH Python WMI Example using ExecNotificationQuery with __InstanceOperationEvent
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="python">
<![CDATA[
import win32com.client
import string
locator = win32com.client.Dispatch("WbemScripting.SWbemLocator")
svc = locator.ConnectServer()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.ExecNotificationQuery("Select * From __InstanceOperationEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
mystr = ""
for obj in Objs:
for prop in Objs.Properties_:
break
]]>
</script>
</job>
</package>
http://www.planetmps.com/wmiscriptsENQ_O.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="python">
<![CDATA[
import win32com.client
import string
locator = win32com.client.Dispatch("WbemScripting.SWbemLocator")
svc = locator.ConnectServer()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.ExecNotificationQuery("Select * From __InstanceOperationEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
mystr = ""
for obj in Objs:
for prop in Objs.Properties_:
break
]]>
</script>
</job>
</package>
WSH Python 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="python">
<![CDATA[
import win32com.client
import string
locator = win32com.client.Dispatch("WbemScripting.SWbemLocator")
svc = locator.ConnectServer()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.ExecNotificationQuery("Select * From __InstanceModificationEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
mystr = ""
for obj in Objs:
for prop in Objs.Properties_:
break
]]>
</script>
</job>
</package>
http://www.planetmps.com/wmiscriptsENQ_M.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="python">
<![CDATA[
import win32com.client
import string
locator = win32com.client.Dispatch("WbemScripting.SWbemLocator")
svc = locator.ConnectServer()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.ExecNotificationQuery("Select * From __InstanceModificationEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
mystr = ""
for obj in Objs:
for prop in Objs.Properties_:
break
]]>
</script>
</job>
</package>
WSH Python 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="python">
<![CDATA[
import win32com.client
import string
locator = win32com.client.Dispatch("WbemScripting.SWbemLocator")
svc = locator.ConnectServer()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.ExecNotificationQuery("Select * From __InstanceDeletionEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
mystr = ""
for obj in Objs:
for prop in Objs.Properties_:
break
]]>
</script>
</job>
</package>
http://www.planetmps.com/wmiscriptsENQ_D.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="python">
<![CDATA[
import win32com.client
import string
locator = win32com.client.Dispatch("WbemScripting.SWbemLocator")
svc = locator.ConnectServer()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.ExecNotificationQuery("Select * From __InstanceDeletionEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
mystr = ""
for obj in Objs:
for prop in Objs.Properties_:
break
]]>
</script>
</job>
</package>
WSH Python 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="python">
<![CDATA[
import win32com.client
import string
locator = win32com.client.Dispatch("WbemScripting.SWbemLocator")
svc = locator.ConnectServer()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.ExecNotificationQuery("Select * From __InstanceCreationEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
mystr = ""
for obj in Objs:
for prop in Objs.Properties_:
break
]]>
</script>
</job>
</package>
http://www.planetmps.com/wmiscriptsENQ_C.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="python">
<![CDATA[
import win32com.client
import string
locator = win32com.client.Dispatch("WbemScripting.SWbemLocator")
svc = locator.ConnectServer()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.ExecNotificationQuery("Select * From __InstanceCreationEvent WITHIN 1 where targetInstance ISA 'Win32_Process'")
mystr = ""
for obj in Objs:
for prop in Objs.Properties_:
break
]]>
</script>
</job>
</package>
WSH Python 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="python">
<![CDATA[
import win32com.client
import string
locator = win32com.client.Dispatch("WbemScripting.SWbemLocator")
svc = locator.ConnectServer()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.ExecQuery("Select * From Win32_Process")
mystr = ""
for obj in Objs:
for prop in Objs.Properties_:
break
]]>
</script>
</job>
</package>
http://www.planetmps.com/wmiscriptsexecquery.html
<?xml version='1.0' encoding='iso-8859-1'?>
<package>
<job>
<script language="python">
<![CDATA[
import win32com.client
import string
locator = win32com.client.Dispatch("WbemScripting.SWbemLocator")
svc = locator.ConnectServer()
svc.Security_.AuthenticationLevel = 0
svc.Security_.ImpersonationLevel = 3
objs = svc.ExecQuery("Select * From Win32_Process")
mystr = ""
for obj in Objs:
for prop in Objs.Properties_:
break
]]>
</script>
</job>
</package>
Subscribe to:
Posts (Atom)