Source language: Translate to:

VBS result to variable

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

VBS result to variable

Postby stevec » Mon May 08, 2017 7:05 pm

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

Re: VBS result to variable

Postby HPW » Mon May 08, 2017 9:39 pm

Hello,

Untested from other post here:

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

Regards
Hans-Peter
User avatar
HPW
 
Posts: 2510
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany

Re: VBS result to variable

Postby stevec » Tue May 09, 2017 5:24 am

Hans;
Thanks.

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


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

Thanks again
Steve
Steve Christensen
stevec
 
Posts: 223
Joined: Fri Apr 15, 2005 7:33 am
Location: Boise, Idaho

Re: VBS result to variable

Postby HPW » Tue May 09, 2017 10:59 am

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
User avatar
HPW
 
Posts: 2510
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany

Re: VBS result to variable

Postby stevec » Tue May 09, 2017 11:55 am

many thanks.
I will try it later. :D :D :D :D :D
Steve Christensen
stevec
 
Posts: 223
Joined: Fri Apr 15, 2005 7:33 am
Location: Boise, Idaho

Re: VBS result to variable

Postby Tony Kroos » Tue May 09, 2017 12:48 pm

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

Re: VBS result to variable

Postby stevec » Tue May 09, 2017 3:54 pm

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

Re: VBS result to variable

Postby stevec » Tue May 09, 2017 4:00 pm

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

Re: VBS result to variable

Postby Tony Kroos » Thu May 11, 2017 2:14 am

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


Return to NeoBook Functions - VBScript & JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest