Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: Windows Server » microsoft.public.windows.server.scripting
Thread: Set WMI return value to a variable...

HTVi
TV Discussion Newsgroups

Set WMI return value to a variable...
"Les" <les[ at ]domain.com> 6/26/2007 8:34:39 PM
The following code gets me the serial # of a PC but instead of just echoing
the serial number I'd like to be able to set it to a variable, ie Set
PCSerial = objItem.SerialNumber
But if I put that line in after the WScript.Echo I get the following error:

C:\Temp\PCSerial.vbs(57, 3) Microsoft VBScript runtime error: Object
required: '[string: "123FF123"]'

How can I capture this info for use as a variable?

Thank you,
Les Bowman

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

'* Query WMI to get the serial number of the PC.
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
'*If the file didn't exist we connect to WMI and get the info.
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BIOS", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WScript.Echo "Serial Number/PC Name is = " & objItem.SerialNumber
Next


Re: Set WMI return value to a variable...
"Michael Harris \(MVP\)" <mikhar.at.mvps.dot.org> 6/26/2007 8:42:19 PM
Les wrote:
[Quoted Text]
> The following code gets me the serial # of a PC but instead of just
> echoing the serial number I'd like to be able to set it to a
> variable, ie Set PCSerial = objItem.SerialNumber
> But if I put that line in after the WScript.Echo I get the following
> error:
>
> C:\Temp\PCSerial.vbs(57, 3) Microsoft VBScript runtime error: Object
> required: '[string: "123FF123"]'
>
> How can I capture this info for use as a variable?
>
> Thank you,
> Les Bowman
>
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>
> '* Query WMI to get the serial number of the PC.
> Set objWMIService = GetObject("winmgmts:\\" & strComputer &
> "\root\CIMV2") '*If the file didn't exist we connect to WMI and get
> the info. Set colItems = objWMIService.ExecQuery("SELECT * FROM
> Win32_BIOS", "WQL", _ wbemFlagReturnImmediately +
> wbemFlagForwardOnly) For Each objItem In colItems
> WScript.Echo "Serial Number/PC Name is = " & objItem.SerialNumber

'no Set, SerialNumber is not an object...
PCSerial = objItem.SerialNumber

> Next

--
Michael Harris
Microsoft.MVP.Scripting


Re: Set WMI return value to a variable...
"Les" <les[ at ]domain.com> 6/26/2007 8:54:29 PM
Thank you Mr. Harris!

"Michael Harris (MVP)" <mikhar.at.mvps.dot.org> wrote in message
news:%23O4Z%23JDuHHA.3796[ at ]TK2MSFTNGP02.phx.gbl...
[Quoted Text]
> Les wrote:
>> The following code gets me the serial # of a PC but instead of just
>> echoing the serial number I'd like to be able to set it to a
>> variable, ie Set PCSerial = objItem.SerialNumber
>> But if I put that line in after the WScript.Echo I get the following
>> error:
>>
>> C:\Temp\PCSerial.vbs(57, 3) Microsoft VBScript runtime error: Object
>> required: '[string: "123FF123"]'
>>
>> How can I capture this info for use as a variable?
>>
>> Thank you,
>> Les Bowman
>>
>> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>>
>> '* Query WMI to get the serial number of the PC.
>> Set objWMIService = GetObject("winmgmts:\\" & strComputer &
>> "\root\CIMV2") '*If the file didn't exist we connect to WMI and get
>> the info. Set colItems = objWMIService.ExecQuery("SELECT * FROM
>> Win32_BIOS", "WQL", _ wbemFlagReturnImmediately +
>> wbemFlagForwardOnly) For Each objItem In colItems
>> WScript.Echo "Serial Number/PC Name is = " & objItem.SerialNumber
>
> 'no Set, SerialNumber is not an object...
> PCSerial = objItem.SerialNumber
>
>> Next
>
> --
> Michael Harris
> Microsoft.MVP.Scripting
>
>


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen