WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WMI
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

WMI and Arrays

 Keywords:  WMI embedded arrays array

Question:

I have been playing around with your WMI example scripts and have run into an issue I was hoping someone could help me out with.

When I query certain Win32 classes like BIOS there are classes that return an array like BiosCharacteristics.

If I use the examples provided I get an error that you cannot created embedded arrays. I have tried to call a function to see if the value is an array but cannot get it to return a 1. Below is an example of the script I am trying to run.

I would like to either skip over the values that are arrays or possibly convert them to a string so that they can be used.


#include "WMI_Function_Library.wbt"
objSvc = WMI_Initialize()
Class = "Win32_BIOS" 

;Define a list of properties
Proplist = ""
Proplist = StrCat(Proplist, "BuildNumber,")
Proplist = StrCat(Proplist, "BiosCharacteristics,")
Proparray=Arrayize(Proplist,",")
Valuearray=ArrDimension(ArrInfo (Proparray, 6))
Instance = 0
msg = "" 
count = ItemCount(Proplist,",")
For x = 0 to Count-1
#DefineFunction IsArray(item)
return(vartype(item)==256)
#Endfunction
bool=IsArray(Proparray[x])

Valuearray[x] = WMI_Get_Property_Value(objSvc, Class,Proparray[x],Instance)
msg = StrCat(msg,@CRLF,Proparray[x]," = ",Valuearray[x])
Next

;Display results
Message(Class,msg)

WMI_Close(objSvc)

Drop(Proparray)
Drop(Valuearray)
Exit 

Answer:

For Win32 classes like BIOS, there are properties that return an array, like BiosCharacteristics, which get automatically returned as a Winbatch array.

WinBatch doesn't support embedded arrays (an array inside of an array). Therefore you will not be able to code the script using array to store the properties. Some of which may be arrays.

I have revised the code to use "lists" instead of arrays to store the data. I also added code to translate the bios characteristics numbers into descriptive strings.

#DefineFunction BiosCharacteristicStr(num)
	Switch num
		case 0 
		msg = "Reserved"
		break 
		case 1 
		msg = "Reserved"
		break  
		case 2 
		msg = "Unknown"
		break  
		case 3 
		msg = "BIOS Characteristics Not Supported"
		break  
		case 4 
		msg = "ISA is supported"
		break  
		case 5 
		msg = "MCA is supported"
		break  
		case 6 
		msg = "EISA is supported"
		break  
		case 7 
		msg = "PCI is supported"
		break  
		case 8 
		msg = "PC Card (PCMCIA) is supported"
		break  
		case 9 
		msg = "Plug and Play is supported"
		break  
		case 10 
		msg = "APM is supported"
		break  
		case 11 
		msg = "BIOS is Upgradable (Flash)"
		break  
		case 12 
		msg = "BIOS shadowing is allowed"
		break  
		case 13 
		msg = "VL-VESA is supported"
		break  
		case 14 
		msg = "ESCD support is available"
		break  
		case 15 
		msg = "Boot from CD is supported"
		break  
		case 16 
		msg = "Selectable Boot is supported"
		break  
		case 17 
		msg = "BIOS ROM is socketed"
		break  
		case 18 
		msg = "Boot From PC Card (PCMCIA) is supported"
		break  
		case 19 
		msg = "EDD (Enhanced Disk Drive) Specification is supported"
		break  
		case 20 
		msg = "Int 13h - Japanese Floppy for NEC 9800 1.2mb (3.5, 1k Bytes/Sector, 360 RPM) is supported"
		break  
		case 21 
		msg = "Int 13h - Japanese Floppy for Toshiba 1.2mb (3.5, 360 RPM) is supported"
		break  
		case 22 
		msg = "Int 13h - 5.25 / 360 KB Floppy Services are supported"
		break  
		case 23 
		msg = "Int 13h - 5.25 /1.2MB Floppy Services are supported"
		break  
		case 24 
		msg = "Int 13h - 3.5 / 720 KB Floppy Services are supported"
		break  
		case 25 
		msg = "Int 13h - 3.5 / 2.88 MB Floppy Services are supported"
		break  
		case 26 
		msg = "Int 5h, Print Screen Service is supported"
		break  
		case 27 
		msg = "Int 9h, 8042 Keyboard services are supported"
		break  
		case 28 
		msg = "Int 14h, Serial Services are supported"
		break  
		case 29 
		msg = "Int 17h, printer services are supported"
		break  
		case 30 
		msg = "Int 10h, CGA/Mono Video Services are supported"
		break  
		case 31 
		msg = "NEC PC-98"
		break  
		case 32 
		msg = "ACPI supported"
		break  
		case 33 
		msg = "USB Legacy is supported"
		break  
		case 34 
		msg = "AGP is supported"
		break  
		case 35 
		msg = "I2O boot is supported"
		break  
		case 36 
		msg = "LS-120 boot is supported"
		break  
		case 37 
		msg = "ATAPI ZIP Drive boot is supported"
		break  
		case 38 
		msg = "1394 boot is supported"
		break  
		case 39 
		msg = "Smart Battery supported"
		break 
		case num
		msg = "**Unknown**"
		break
	EndSwitch
	return(msg)
#EndFunction

#DefineFunction IsArray(item)
	return(vartype(item)==256)
#Endfunction


#include "WMI_Function_Library.wbt"
objSvc = WMI_Initialize()
Class = "Win32_BIOS" 

;Define a list of properties
Proplist = ""
Proplist = StrCat(Proplist, "BuildNumber,")
Proplist = StrCat(Proplist, "BiosCharacteristics")

Instance = 0
msg = "" 
propcount = ItemCount(Proplist,",")
For x = 1 to propcount
   item = ItemExtract(x,Proplist,",")
	value = WMI_Get_Property_Value(objSvc, Class, item,Instance)
	ret = IsArray(value)
	;Check if property is an array, if so change to a string
	if ret==@true 
		Message(item,"Is an array")
		;count items
		  count = ArrInfo(value,1)
		  charlist = ""
		  For y =  0 to count-1
			  charnum = value[y]
			  charstr = BiosCharacteristicStr(charnum)
			  charlist = StrCat(charlist,@tab,charstr)
		  Next
		  ;trim off leading tab
		  charlist = StrTrim(charlist)
		  ;replace tabs with carriage retrun line feeds for display
		  value = StrReplace(charlist,@tab,@crlf)
	endif
	msg = StrCat(msg,@CRLF,Item," = ",Value)
Next

;Display results
Message(Class,msg)

WMI_Close(objSvc)

Drop(Proparray)
Drop(Valuearray)
Exit 

Article ID:   W16276
File Created: 2004:03:30:15:43:44
Last Updated: 2004:03:30:15:43:44