Page 1 of 1

VBS result to variable

PostPosted: Mon May 08, 2017 7:05 pm
by stevec
I have a VBS scrpit, now a function, using the 'Call' to run it, I'd like to save the result into a variable.

The code get the PC serial number.

*************code**************

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

Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_ComputerSystemProduct")
For Each objItem in colItems
msgbox "This Device: " & objItem.IdentifyingNumber, vbOkayOnly, "Serial Number"
Next

****************end Code***************

How can I get the result to save to a variable?

Thanks;

Re: VBS result to variable

PostPosted: Mon May 08, 2017 9:39 pm
by HPW
Hello,

Untested from other post here:

publication.nbSetVar "[xxx]", "retstring"

Regards

Re: VBS result to variable

PostPosted: Tue May 09, 2017 5:24 am
by stevec
Hans;
Thanks.

Were would the code be placed? and [xxx] is the variable, correct?


publication.nbSetVar "[xxx]", "retstring"

Thanks again
Steve

Re: VBS result to variable

PostPosted: Tue May 09, 2017 10:59 am
by HPW
Hello,

The code was only a sample.
It must be placed into your vb-code.
It might be something like:
publication.nbSetVar "[YourWantedNbVariable]", "objItem.IdentifyingNumber"

Since you Output your msbbox in a Loop you might nedd a Counter to build a variable-Name for each Iteration.

Regards

Re: VBS result to variable

PostPosted: Tue May 09, 2017 11:55 am
by stevec
many thanks.
I will try it later. :D :D :D :D :D

Re: VBS result to variable

PostPosted: Tue May 09, 2017 12:48 pm
by Tony Kroos
Code: Select all
On Error Resume Next
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colItems = objWMI.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct")
For Each objItem in colItems
i = i + 1
nbSetVar "[Product"&i&"]", objItem.Name & "|" & objItem.IdentifyingNumber
Next
Set objWMI = Nothing
Set colItems = Nothing

Minimum supported client - Windows Vista

Re: VBS result to variable

PostPosted: Tue May 09, 2017 3:54 pm
by stevec
Thanks;

The code returns the following

HP Compaq 8000 Elite CMT PC|2UA0291LLB

I just need the "2UA0291LLB" - no quotes. I have attempted to edit the string. UGH!

I got the code to give |2UA0291LLB

Thanks;
Steve

Re: VBS result to variable

PostPosted: Tue May 09, 2017 4:00 pm
by stevec
Thanks!!!!!!

I got it.

nbSetVar "[Product"&i&"]", "" & objItem.IdentifyingNumber

by eliminating the "|", I was able to get what I needed.

AWESOME!!!!

Many thanks!

Steve :D :D :D

Re: VBS result to variable

PostPosted: Thu May 11, 2017 2:14 am
by Tony Kroos
My previous message was about how to handle and pass arrays to Neobook.
If you really sure that script won't return an array of hardware devices, then you may just take first ID in collection:
Code: Select all
On Error Resume Next
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colItems = objWMI.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct")
For Each objItem in colItems
nbSetVar "[ProductID]", objItem.IdentifyingNumber
Exit For
Next
Set objWMI = Nothing
Set colItems = Nothing