View Full Version : VBScript and WMI in HTML "HELP ME, PLEASE!"

Amanda Wansley
04-19-2004, 06:02 PM
:confused: I am an intern with the task of writting some software for a hardware database. I need to output some WMI into an HTML file, then be able to edit it after it is output.Here is the code I am using. How do I do that? I really need help!

strComputer = "."
strComputer = InputBox("Please enter the name of the computer [insert a period '.'] for the current machine")
If strComputer = "" Then
End If

CRLF = Chr(13) & Chr(10) ' carriage return, line feed
strmsg = ""
filename = ""

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)

For Each objItem in colItems
Memformat = Cint(objItem.TotalPhysicalMemory/1000000)
strmsg=strmsg & "Manufacturer: " & objItem.Manufacturer & CRLF
strmsg=strmsg & "Model: " & objItem.Model & CRLF
strmsg=strmsg & "Name: " & objItem.Name & CRLF
' strmsg=strmsg & "Total Memory: " & objItem.TotalPhysicalMemory & CRLF
strmsg=strmsg & "Memory (MB): " & Memformat & CRLF
filename =filename & objItem.Name

I'm looking to output information about the current machine that the program is running on. i.e. Model, Memory, Mac address. etc. Then once the program has pulled this info up into a webpage, we want to be able to massage the data (edit it) then send it to a database. You would ideally use ASP for this, but right now we do not have the resources to do that, so we're trying to find a short term solution to the problem, so we won't have to key in the data. Which as you know results in finger slips, and curruption of the data.
We have alot of new hardware coming in, and really no defined database. So the long term goal is to use what we learn doing this little chunk right here, and then try to expand the idea.

I first thought to make the code above a sub procedure, then call it from javascript, maybe a document.write or span. But I really have no clue. The main thing I am having trouble with is getting the outputted info in to an Html file, and in a way that it can then be edited. But not copy and pasted. I don't know if this helps you or not.

04-20-2004, 12:23 AM
Forwarding to the programming forum...

Also, could you please post more details on what you need (what are your current results and what are you looking for???)


04-22-2004, 05:01 AM
I rewrote it a tad, it works as a hypertext application, but I get ActiveX errors trying to use WMI in an HTML page. This works if you save it as a .hta file instead of HTML...and run it locally as a hypertext application.
from Microsoft KB article:

"In HTML pages running in Microsoft Internet Explorer (IE), GetObject and CreateObject can fail because WMI scripting objects, like ActiveX controls, are not marked as safe for scripting. The one exception is the SWbemDateTime object. The only way that these calls can succeed is when you lower the IE security settings, which is not recommended.

On Active Server Pages (ASP) you can use GetObject or CreateObject in the server-side script. For more information, see Creating Active Server Pages for WMI."

Border = Thick
BorderStyle = Complex
ShowInTaskBar = No
MaximizeButton = No
MinimizeButton = No
<script language="vbscript">

Sub window_onLoad

Set objDocument = self.Document

objdocument.WriteLn "<title>OneMore</title>"
objdocument.WriteLn "<h2>One More</h2><hr>"

'strComputer = "."
strComputer = InputBox("Please enter the name of the computer[insert a period '.'] for the current machine")
If strComputer = "" Then
wscript (0)
End If

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)

For Each ObjItem in colItems

Dim Name
Dim Model
Dim Memformat

Memformat = Cint(objItem.TotalPhysicalMemory/1048576)
Model ="Model: " & objItem.Model
Name ="Name: " & objItem.Name

objdocument.WriteLn Model &"<br>"
objdocument.WriteLn Name &"<br>"
objdocument.WriteLn "Memory: " & Memformat &"<br>"

End Sub





and here's a file with some examples of how to pull other WMI related info....note: you don't have to keep connecting to WMI over and over, you just have to do it once per script, but I have it there so I can copy/paste when needed. You'll have to make changes....like using objdocument.WriteLn instead of wscript echo, but I thought it might be helpful.