VBS result to variable
Moderator: Neosoft Support
VBS result to variable
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;
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
Re: VBS result to variable
Hello,
Untested from other post here:
publication.nbSetVar "[xxx]", "retstring"
Regards
Untested from other post here:
publication.nbSetVar "[xxx]", "retstring"
Regards
Hans-Peter
Re: VBS result to variable
Hans;
Thanks.
Were would the code be placed? and [xxx] is the variable, correct?
publication.nbSetVar "[xxx]", "retstring"
Thanks again
Steve
Thanks.
Were would the code be placed? and [xxx] is the variable, correct?
publication.nbSetVar "[xxx]", "retstring"
Thanks again
Steve
Steve Christensen
Re: VBS result to variable
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
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
-
- Posts: 419
- Joined: Thu Oct 15, 2009 3:43 pm
Re: VBS result to variable
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
Re: VBS result to variable
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
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
Re: VBS result to variable
Thanks!!!!!!
I got it.
nbSetVar "[Product"&i&"]", "" & objItem.IdentifyingNumber
by eliminating the "|", I was able to get what I needed.
AWESOME!!!!
Many thanks!
Steve
I got it.
nbSetVar "[Product"&i&"]", "" & objItem.IdentifyingNumber
by eliminating the "|", I was able to get what I needed.
AWESOME!!!!
Many thanks!
Steve
Steve Christensen
-
- Posts: 419
- Joined: Thu Oct 15, 2009 3:43 pm
Re: VBS result to variable
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:
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