3

I'm trying to run some commands based on OS and x86 vs. x64. When running the below code the variable remains blank. I can echo the output and see the query and property seem to be correct. Any idea why that string isn't being assigned tot he variable named osbit?

strOSbit = "SELECT * FROM Win32_Processor"

Set colItems = objWMIService.ExecQuery(strOSbit, "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItems
  Set osbit = objItem.AddressWidth
Next
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
David
  • 31
  • 1
  • 1
    Does the script error, if so what is the specific error? – user692942 Nov 03 '16 at 15:43
  • 4
    From your script the most obvious thing is both `wbemFlagReturnImmediately` and `wbemFlagForwardOnly` are not defined, VBScript does not know about the WMI type library so you have to define the Named Constants manually using `Const nameofconstant = value` so for example `Const wbemFlagForwardOnly = 32`. List of `WbemFlagEnum` constants [here](https://msdn.microsoft.com/en-us/library/aa393980(v=vs.85).aspx). – user692942 Nov 03 '16 at 16:13
  • 3
    `AddressWidth` is `UInt16` type in WMI repository (a _Variant_ subtype `Integer` in VBScript ) so you should use `osbit = objItem.AddressWidth` as `SET` statement assigns an **object reference** to a variable or property, or associates a **procedure reference** with an event. – JosefZ Nov 03 '16 at 20:03
  • Really, `TypeName(objItem.AddressWidth)` returns `Long` subtype :))) – JosefZ Nov 03 '16 at 20:19
  • 3
    @JosefZ `UInt16` means 16-bit unsigned integer. Since VBScript's integer is 16-bit and **signed**, *as well as all other numerical variant subtypes in VBScript*, mapping `Long` is quite logical. – Kul-Tigin Nov 03 '16 at 20:58
  • 1
    @Kul-Tigin of course. I have forgotten that VBScript `integer` is only 16 bit value. Confused with `[int]` in Powershell which is `[int32]` :-( – JosefZ Nov 03 '16 at 22:16

0 Answers0