| Welcome To PlanetMPs.com |
|
Here's an example on how to use wmi with ASP |
|
<%@ LANGUAGE="VBSCRIPT"%>
<HTML>
<HEAD>
<TITLE>Win32_Process</TITLE>
</HEAD>
<BODY>
<%
On Error Resume Next
Const wbemFlagReturnImmediately = &H10
Const wbemFlagForwardOnly = &H20
strComputerName="."
Set lctr = CreateObject("WbemScripting.SWbemLocator")
Set Service = lctr.connectServer(strComputerName, "root\cimv2")
Service.Security_.AuthenticationLevel=6
Service.Security_.ImpersonationLevel=3
set objs = service.InstancesOf("Win32_Process")
response.write("<table cellpadding=3 cellspacing=3>" & vbcrlf)
response.write("<caption>Win32_Process</caption>" & vbcrlf)
for each obj in objs
response.write("<tr>" & vbcrlf)
for each prop in obj.Properties_
response.write("<th align=left nowrap>" & prop.Name & "</th>" & vbcrlf)
Next
response.write("</tr>" & vbcrlf)
Exit For
Next
for each obj in objs
response.write("<tr>" & vbcrlf)
for each prop in obj.Properties_
response.write("<td align=left nowrap>" & GetValue(prop.Name, obj) & "</td>" & vbcrlf)
response.write("</tr>" & vbcrlf)
Next
response.write("</table>" & vbcrlf)
Function GetValue(name, obj)
pos = InStr(obj.GetObjectText_, Name & " = ")
If pos Then
tempstr = Mid(obj.GetObjectText_, pos + Len(Name & " = "), Len(obj.GetObjectText_))
pos = InStr(tempstr, ";")
tempstr = Mid(tempstr, 1, pos - 1)
tempstr = Replace(tempstr, Chr(34), "")
tempstr = Replace(tempstr, "{", "")
tempstr = Replace(tempstr, "}", "")
if len(tempstr) > 13 And obj.Properties_(name).CIMType = 101 Then
tempstr = WMIDateStringToDate(tempstr)
End If
GetValue = tempstr
Else
GetValue = ""
End If
End Function
Function WMIDateStringToDate(UTCDATE)
WMIDateStringToDate = Mid(UTCDATE, 5, 2) & "/" & _
Mid(UTCDATE, 7, 2) & "/" & _
Mid(UTCDATE, 1, 4) & " " & _
Mid(UTCDATE, 9, 2) & ":" & _
Mid(UTCDATE, 11, 2) & ":" & _
Mid(UTCDATE, 13, 2)
End Function
%>
</BODY>
</HTML>
|