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.

Physical Memory Inspection


 #DefineFunction WMI_Get_All_Instances(ObjectServiceArray,Classname,Property)
	objService = ObjectServiceArray[0]
	Value=""
	Str = ""
	WMIObj = objService.InstancesOf(Classname)
	hEnum = ObjectCollectionOpen(WMIObj)
	While 1
	  Obj = ObjectCollectionNext(hEnum)
	  If Obj == 0 then Break
	  Value = Obj.%Property%
	  Str = StrCat(Str,@tab,Value)
	EndWhile
	Str = StrTrim(Str)
	ObjectCollectionClose(hEnum)
	ObjectClose(WMIObj)
	Return Str
#EndFunction
#DefineFunction IsArray(item)
	return(vartype(item)==256)
#Endfunction
#DefineFunction WMI_Initialize()
	objLocator = ObjectOpen("WbemScripting.SWbemLocator")
	objService = objLocator.ConnectServer()
	objSecurity = objService.Security_ ;Do not remove underscore
	objSecurity.ImpersonationLevel = 3
	ObjectServiceArray=ArrDimension(3)
	ObjectServiceArray[0] = objService
	ObjectServiceArray[1] = objLocator
	ObjectServiceArray[2] = objSecurity
Return ObjectServiceArray
#EndFunction
#DefineFunction WMI_Close(ObjectServiceArray)
	ObjectClose(ObjectServiceArray[0]) ;objService
	ObjectClose(ObjectServiceArray[1]) ;objLocator
	ObjectClose(ObjectServiceArray[2]) ;objSecurity 
return 1
#EndFunction
#DefineFunction WMI_Get_Property_Value(ObjectServiceArray,Classname,Property,Instance)
	objService = ObjectServiceArray[0]
	Value=""
	Obj = WMI_Get_Object(ObjectServiceArray,Classname,Instance)
	Value = Obj.%Property%
   Return Value
#EndFunction
#DefineFunction WMI_Get_Object(ObjectServiceArray,Classname,Instance)
	objService=ObjectServiceArray[0]
	Str = ""
	WMIObj = objService.InstancesOf(Classname)
	hEnum = ObjectCollectionOpen(WMIObj)	
	InstanceFound = 1
	for InstanceCnt=0 to Instance
	  Obj = ObjectCollectionNext(hEnum)
	  If Obj == 0
	      InstanceFound = 0
	      Break
	  endif
	next	
	ObjectCollectionClose(hEnum)
	ObjectClose(WMIObj)
	if InstanceFound == 1
	    Return Obj
	Else
	   Message("WMI_Get_Object Error","Instance specified was not found")
		Return 0
	Endif
#EndFunction
objSvc = WMI_Initialize()
Class =  "Win32_PhysicalMemory" 
;Define a list of properties
Proplist = ""
    Proplist = StrCat(Proplist, "BankLabel,")
    Proplist = StrCat(Proplist, "Capacity,")
    Proplist = StrCat(Proplist, "Caption,")
    Proplist = StrCat(Proplist, "CreationClassName,")
    Proplist = StrCat(Proplist, "DataWidth,")
    Proplist = StrCat(Proplist, "Description,")
    Proplist = StrCat(Proplist, "DeviceLocator,")
    Proplist = StrCat(Proplist, "FormFactor,")
    Proplist = StrCat(Proplist, "HotSwappable,")
    Proplist = StrCat(Proplist, "InstallDate,")
    Proplist = StrCat(Proplist, "InterleaveDataDepth,")
    Proplist = StrCat(Proplist, "InterleavePosition,")
    Proplist = StrCat(Proplist, "Manufacturer,")
    Proplist = StrCat(Proplist, "MemoryType,")
    Proplist = StrCat(Proplist, "Model,")
    Proplist = StrCat(Proplist, "Name,")
    Proplist = StrCat(Proplist, "OtherIdentifyingInfo,")
    Proplist = StrCat(Proplist, "PartNumber,")
    Proplist = StrCat(Proplist, "PositionInRow,")
    Proplist = StrCat(Proplist, "PoweredOn,")
    Proplist = StrCat(Proplist, "Removable,")
    Proplist = StrCat(Proplist, "Replaceable,")
    Proplist = StrCat(Proplist, "SerialNumber,")
    Proplist = StrCat(Proplist, "SKU,")
    Proplist = StrCat(Proplist, "Speed,")
    Proplist = StrCat(Proplist, "Status,")
    Proplist = StrCat(Proplist, "Tag,")
    Proplist = StrCat(Proplist, "TotalWidth,")
    Proplist = StrCat(Proplist, "TypeDetail,")
    Proplist = StrCat(Proplist, "Version,")
;Need to Trim the comma from the last property
Proplen = StrLen(Proplist) - 1
Proplist = StrFix(Proplist,"", Proplen)
list = ""
PropDesc = "Description"
	list = WMI_Get_All_Instances(objSvc, Class,PropDesc)
	listcount = ItemCount(list,@tab)
	 If listcount==1
		instance=0
		GoTo GetProps
	 Else
		GoTo retry
	 Endif& Chr(10) 
	:retry
	instancename = AskItemList(StrCat("List of '",PropDesc,"' properties in '",Class,"' Class"),list,@tab,@unsorted,@single)
	if instancename=="" then goto retry
	instance = ItemLocate(instancename,list,@tab)
	;Instances are zero based
	instance = instance-1
:GetProps
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 
		  count = ArrInfo(value,1)
		  charlist = ""
		  For y =  0 to count-1
			  charnum = value[y]
			  charlist = StrCat(charlist,@tab,charnum)
		  Next
		  charlist = StrTrim(charlist)
		  value = StrReplace(charlist,@tab,", ")
	endif
	msg = StrCat(msg,@CRLF,Item," = ",Value)
Next
;Display results
Message(Class,msg)
WMI_Close(objSvc)
Drop(Proparray)
Drop(Valuearray)
Exit 

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