VBS result to variable

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

Locked
stevec
Posts: 226
Joined: Fri Apr 15, 2005 7:33 am
Location: Boise, Idaho

VBS result to variable

Post 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;
Steve Christensen
User avatar
HPW
Posts: 2571
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany
Contact:

Re: VBS result to variable

Post by HPW »

Hello,

Untested from other post here:

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

Regards
Hans-Peter
stevec
Posts: 226
Joined: Fri Apr 15, 2005 7:33 am
Location: Boise, Idaho

Re: VBS result to variable

Post by stevec »

Hans;
Thanks.

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


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

Thanks again
Steve
Steve Christensen
User avatar
HPW
Posts: 2571
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany
Contact:

Re: VBS result to variable

Post 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
Hans-Peter
stevec
Posts: 226
Joined: Fri Apr 15, 2005 7:33 am
Location: Boise, Idaho

Re: VBS result to variable

Post by stevec »

many thanks.
I will try it later. :D :D :D :D :D
Steve Christensen
Tony Kroos
Posts: 419
Joined: Thu Oct 15, 2009 3:43 pm

Re: VBS result to variable

Post 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
stevec
Posts: 226
Joined: Fri Apr 15, 2005 7:33 am
Location: Boise, Idaho

Re: VBS result to variable

Post 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
Steve Christensen
stevec
Posts: 226
Joined: Fri Apr 15, 2005 7:33 am
Location: Boise, Idaho

Re: VBS result to variable

Post 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
Steve Christensen
Tony Kroos
Posts: 419
Joined: Thu Oct 15, 2009 3:43 pm

Re: VBS result to variable

Post 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
Locked