trabajar con WMI y ver resultados con xml

I am new in vbscript and WMI. I wrote script which gives runtime error, that I cant solve. If you have a time help me.

Este es mi codigo

Dim objWMIService 
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

set oXMLDoc = CreateObject("Microsoft.XMLDOM")
set oRoot = oXMLDoc.CreateElement("WIN32")

oXMLDoc.appendChild oRoot

set oRootChild = oXMLDoc.createElement("LOGICALDISK")
oRoot.appendChild oRootChild

Set LogicalDisk = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk  ")

for each objLogicalDisk in LogicalDisk

set oCaption = oXMLDoc.createElement("Caption")
oCaption.text = objLogicalDisk.Caption
oRootChild.appendChild oCaption

set oDescription = oXMLDoc.createElement("Description")
oDescription.text = objLogicalDisk.Description
oCaption.appendChild oDescription

set oSize = oXMLDoc.createElement("Size")
oSize.text = objLogicalDisk.Size
oCaption.appendChild oSize

set oFreeSpace = oXMLDoc.createElement("FreeSpace")
oFreeSpace.text = objLogicalDisk.FreeSpace
oCaption.appendChild oFreeSpace

set oFileSystem = oXMLDoc.createElement("FileSystem")
oFileSystem.text = objLogicalDisk.FileSystem
oCaption.appendChild oFileSystem

next "test.xml"

And it gives this error

C:\Users\XXXX\Desctop\41.vbs(27, 1) Microsoft VBScript runtime error: Type mismatch: 'oSize.text'

I thing that error occurs because of using uint64 type.(may be not)

preguntado el 10 de marzo de 12 a las 14:03

This error is due to Devices with Removable Storage -

2 Respuestas

Your problem is caused by Null values. Start with a function like

Function saveNull(vVal)
  If IsNull(vVal) Then
     saveNull = "<null>"
     saveNull = vVal
  End If
End Function

y utilícelo como:

set oSize = oXMLDoc.createElement("Size")
oSize.text = saveNull(objLogicalDisk.Size)
oCaption.appendChild oSize

WRT AMO1's contibution:

Empty "removable storage" drives have neither size nor file system (facts which WMI reports by returning Null); checking the description to in/exclude specific drive types does not solve the problem, because inserting a media in such a drive makes those info available.

respondido 10 mar '12, 17:03

I have verified With Removable Storage & inserting media in it makes those info available.Thus your solution is more correct than mine & my solution will work only for Local storage +1 For your Detail - Amol Chavan

This error is due to "Devices with Removable Storage".I am sure as size not working ,FreeSpace & FileSystem will also not work.You can overcome it by adding If <condtion> then. Sample code

set oSize = oXMLDoc.createElement("Size")
If objLogicalDisk.Description="Local Fixed Disk" Then
oSize.text = objLogicalDisk.Size
oCaption.appendChild oSize
End If

respondido 10 mar '12, 16:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.