Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - what does the '48' mean?

Reply
 
Old 08-05-2008   #1 (permalink)
Tony Logan


 
 

what does the '48' mean?

Found a script that tries to determine whether a PC is a desktop or laptop.
One of the lines of code is:
Set colItems = objWMIService.ExecQuery( "Select * from Win32_Battery", , 48 )
Does anyone know what the 48 refers to?
Thanks.

My System SpecsSystem Spec
Old 08-05-2008   #2 (permalink)
PaulM


 
 

Re: what does the '48' mean?

48 brings up a yellow box with an Exclamation mark in it.


"Tony Logan" <TonyLogan@xxxxxx> wrote in message
news:4B1DD4D9-325C-4CE0-9FC3-938A94D51271@xxxxxx
Quote:

> Found a script that tries to determine whether a PC is a desktop or
> laptop.
> One of the lines of code is:
> Set colItems = objWMIService.ExecQuery( "Select * from Win32_Battery", ,
> 48 )
> Does anyone know what the 48 refers to?
> Thanks.
My System SpecsSystem Spec
Old 08-05-2008   #3 (permalink)
urkec


 
 

RE: what does the '48' mean?

"Tony Logan" wrote:
Quote:

> Found a script that tries to determine whether a PC is a desktop or laptop.
> One of the lines of code is:
> Set colItems = objWMIService.ExecQuery( "Select * from Win32_Battery", , 48 )
> Does anyone know what the 48 refers to?
> Thanks.

48 = wbemFlagForwardOnly (32) + wbemFlagReturnImmediately (16), which means
that you can enumerate colItems only once and you can't use colItems.Count.
Also, if there is an error, it is not reported untill you try to access
colItems.

--
urkec



My System SpecsSystem Spec
Old 08-05-2008   #4 (permalink)
Paul Randall


 
 

Re: what does the '48' mean?


"urkec" <urkec@xxxxxx> wrote in message
news:9DB1C913-DBCD-4384-ABEB-420C3DDF9242@xxxxxx
Quote:

> "Tony Logan" wrote:
>
Quote:

>> Found a script that tries to determine whether a PC is a desktop or
>> laptop.
>> One of the lines of code is:
>> Set colItems = objWMIService.ExecQuery( "Select * from Win32_Battery", ,
>> 48 )
>> Does anyone know what the 48 refers to?
>> Thanks.
>
>
> 48 = wbemFlagForwardOnly (32) + wbemFlagReturnImmediately (16), which
> means
> that you can enumerate colItems only once and you can't use
> colItems.Count.
> Also, if there is an error, it is not reported untill you try to access
> colItems.
I see that TypeName(colItems) returns SWbemObjectSet whether the collection
contains any items or not. I'm hoping you or someone has a way to find out
if the collection has any items without resorting to handling the error that
occurs when you try to access it.

Also, is it necessary to use the two flags in the 48? Can other, more
friendly flags be used? If so, what might they be?

Thanks in advance,
-Paul Randall


My System SpecsSystem Spec
Old 08-05-2008   #5 (permalink)
Al Dunbar


 
 

Re: what does the '48' mean?


"Paul Randall" <paulr90@xxxxxx> wrote in message
news:OchrrR09IHA.4456@xxxxxx
Quote:

>
> "urkec" <urkec@xxxxxx> wrote in message
> news:9DB1C913-DBCD-4384-ABEB-420C3DDF9242@xxxxxx
Quote:

>> "Tony Logan" wrote:
>>
Quote:

>>> Found a script that tries to determine whether a PC is a desktop or
>>> laptop.
>>> One of the lines of code is:
>>> Set colItems = objWMIService.ExecQuery( "Select * from Win32_Battery", ,
>>> 48 )
>>> Does anyone know what the 48 refers to?
>>> Thanks.
>>
>>
>> 48 = wbemFlagForwardOnly (32) + wbemFlagReturnImmediately (16), which
>> means
>> that you can enumerate colItems only once and you can't use
>> colItems.Count.
>> Also, if there is an error, it is not reported untill you try to access
>> colItems.
>
> I see that TypeName(colItems) returns SWbemObjectSet whether the
> collection contains any items or not. I'm hoping you or someone has a way
> to find out if the collection has any items without resorting to handling
> the error that occurs when you try to access it.
>
> Also, is it necessary to use the two flags in the 48? Can other, more
> friendly flags be used? If so, what might they be?
I don't know, but this is certainly a good illustration of the value of
making good use of constants as a way to make the intent of one's code
clearer.

/Al


My System SpecsSystem Spec
Old 08-06-2008   #6 (permalink)
ekkehard.horner


 
 

Re: what does the '48' mean?

Paul Randall schrieb:
Quote:

> "urkec" <urkec@xxxxxx> wrote in message
> news:9DB1C913-DBCD-4384-ABEB-420C3DDF9242@xxxxxx
Quote:

>> "Tony Logan" wrote:
>>
Quote:

>>> Found a script that tries to determine whether a PC is a desktop or
>>> laptop.
>>> One of the lines of code is:
>>> Set colItems = objWMIService.ExecQuery( "Select * from Win32_Battery", ,
>>> 48 )
>>> Does anyone know what the 48 refers to?
>>> Thanks.
>>
>> 48 = wbemFlagForwardOnly (32) + wbemFlagReturnImmediately (16), which
>> means
>> that you can enumerate colItems only once and you can't use
>> colItems.Count.
>> Also, if there is an error, it is not reported untill you try to access
>> colItems.
>
> I see that TypeName(colItems) returns SWbemObjectSet whether the collection
> contains any items or not. I'm hoping you or someone has a way to find out
> if the collection has any items without resorting to handling the error that
> occurs when you try to access it.
>
> Also, is it necessary to use the two flags in the 48? Can other, more
> friendly flags be used? If so, what might they be?
>
> Thanks in advance,
> -Paul Randall
>
>
A list of flags to use with .ExecQuery can be found here

http://msdn.microsoft.com/en-us/libr...70(VS.85).aspx

or here:

http://msdn.microsoft.com/en-us/libr...07(VS.85).aspx

For (some of) the numerical values see

http://msdn.microsoft.com/en-us/library/cc215511.aspx
http://msdn.microsoft.com/en-us/library/cc215515.aspx

To make sure and to get a complete list, look into the pertinent header
file (provider.h (?)).

Whether all flags work as expected with your version of OS, WSH, VBScript,
and WMI remains to be seen.



My System SpecsSystem Spec
Old 08-06-2008   #7 (permalink)
urkec


 
 

Re: what does the '48' mean?

"Paul Randall" wrote:
Quote:

>
> "urkec" <urkec@xxxxxx> wrote in message
> news:9DB1C913-DBCD-4384-ABEB-420C3DDF9242@xxxxxx
Quote:

> > "Tony Logan" wrote:
> >
Quote:

> >> Found a script that tries to determine whether a PC is a desktop or
> >> laptop.
> >> One of the lines of code is:
> >> Set colItems = objWMIService.ExecQuery( "Select * from Win32_Battery", ,
> >> 48 )
> >> Does anyone know what the 48 refers to?
> >> Thanks.
> >
> >
> > 48 = wbemFlagForwardOnly (32) + wbemFlagReturnImmediately (16), which
> > means
> > that you can enumerate colItems only once and you can't use
> > colItems.Count.
> > Also, if there is an error, it is not reported untill you try to access
> > colItems.
>
> I see that TypeName(colItems) returns SWbemObjectSet whether the collection
> contains any items or not. I'm hoping you or someone has a way to find out
> if the collection has any items without resorting to handling the error that
> occurs when you try to access it.
>
> Also, is it necessary to use the two flags in the 48? Can other, more
> friendly flags be used? If so, what might they be?
>
> Thanks in advance,
> -Paul Randall
>
>
>
The default is wbemFlagReturnImmediately (16), and if you don't use any
other flags, you can use colItems.Count (even if the collection is empty) and
enumerate it more than once:


Set colItems = objWMIService.ExecQuery _
("Select * from Win32_Battery")

WScript.Echo TypeName(colItems)
WScript.Echo colItems.Count

For Each objItem In colItems
WScript.Echo objItem.Name
Next


If you use wbemFlagForwardOnly (32), you can't use colItems.Count and you
can enumerate it only once:


Set colItems = objWMIService.ExecQuery _
("Select * from Win32_Battery", , _
wbemFlagReturnImmediately + wbemFlagForwardOnly)

WScript.Echo TypeName(colItems)
'WScript.Echo colItems.Count

For Each objItem In colItems
WScript.Echo objItem.Name
Next


If you use wbemFlagReturnImmediately and there is an error, it is reported
only when you try to use colItems


Set colItems = objWMIService.ExecQuery _
("Select * from Win32_InvalidClass", , _
wbemFlagReturnImmediately + wbemFlagForwardOnly)

' The error is reported here
For Each objItem In colItems
WScript.Echo objItem.Name
Next


If you use wbemFlagReturnWhenComplete (0) the error is reported on ExecQuery
call:


' The error is reported here
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_InvalidClass", , _
wbemFlagReturnWhenComplete)

For Each objItem In colItems
WScript.Echo objItem.Name
Next


--
urkec
My System SpecsSystem Spec
Old 08-06-2008   #8 (permalink)
Paul Randall


 
 

Re: what does the '48' mean?


"urkec" <urkec@xxxxxx> wrote in message
news:9C202CA9-CFF3-4D6D-995C-B03656B668AA@xxxxxx
Quote:

> "Paul Randall" wrote:
>
Quote:

>>
>> "urkec" <urkec@xxxxxx> wrote in message
>> news:9DB1C913-DBCD-4384-ABEB-420C3DDF9242@xxxxxx
Quote:

>> > "Tony Logan" wrote:
>> >
>> >> Found a script that tries to determine whether a PC is a desktop or
>> >> laptop.
>> >> One of the lines of code is:
>> >> Set colItems = objWMIService.ExecQuery( "Select * from Win32_Battery",
>> >> ,
>> >> 48 )
>> >> Does anyone know what the 48 refers to?
>> >> Thanks.
>> >
>> >
>> > 48 = wbemFlagForwardOnly (32) + wbemFlagReturnImmediately (16), which
>> > means
>> > that you can enumerate colItems only once and you can't use
>> > colItems.Count.
>> > Also, if there is an error, it is not reported untill you try to access
>> > colItems.
>>
>> I see that TypeName(colItems) returns SWbemObjectSet whether the
>> collection
>> contains any items or not. I'm hoping you or someone has a way to find
>> out
>> if the collection has any items without resorting to handling the error
>> that
>> occurs when you try to access it.
>>
>> Also, is it necessary to use the two flags in the 48? Can other, more
>> friendly flags be used? If so, what might they be?
>>
>> Thanks in advance,
>> -Paul Randall
Quote:

> If you use wbemFlagForwardOnly (32), you can't use colItems.Count and you
> can enumerate it only once:
To me that indicates the 32 flag means 'Please, please, please, give me the
most obstinate, useless type of collection'. Why would anyone knowingly ask
for this? Is it quicker, use less resourses, or ???

-Paul Randall


My System SpecsSystem Spec
Old 08-06-2008   #9 (permalink)
Paul Randall


 
 

Re: what does the '48' mean?


"Paul Randall" <paulr90@xxxxxx> wrote in message
news:ORgXYr%239IHA.3344@xxxxxx
Quote:

>
> "urkec" <urkec@xxxxxx> wrote in message
> news:9C202CA9-CFF3-4D6D-995C-B03656B668AA@xxxxxx
Quote:

>> "Paul Randall" wrote:
>>
Quote:

>>>
>>> "urkec" <urkec@xxxxxx> wrote in message
>>> news:9DB1C913-DBCD-4384-ABEB-420C3DDF9242@xxxxxx
>>> > "Tony Logan" wrote:
>>> >
>>> >> Found a script that tries to determine whether a PC is a desktop or
>>> >> laptop.
>>> >> One of the lines of code is:
>>> >> Set colItems = objWMIService.ExecQuery( "Select * from
>>> >> Win32_Battery", ,
>>> >> 48 )
>>> >> Does anyone know what the 48 refers to?
>>> >> Thanks.
>>> >
>>> >
>>> > 48 = wbemFlagForwardOnly (32) + wbemFlagReturnImmediately (16), which
>>> > means
>>> > that you can enumerate colItems only once and you can't use
>>> > colItems.Count.
>>> > Also, if there is an error, it is not reported untill you try to
>>> > access
>>> > colItems.
>>>
>>> I see that TypeName(colItems) returns SWbemObjectSet whether the
>>> collection
>>> contains any items or not. I'm hoping you or someone has a way to find
>>> out
>>> if the collection has any items without resorting to handling the error
>>> that
>>> occurs when you try to access it.
>>>
>>> Also, is it necessary to use the two flags in the 48? Can other, more
>>> friendly flags be used? If so, what might they be?
>>>
>>> Thanks in advance,
>>> -Paul Randall
>
Quote:

>> If you use wbemFlagForwardOnly (32), you can't use colItems.Count and you
>> can enumerate it only once:
>
> To me that indicates the 32 flag means 'Please, please, please, give me
> the most obstinate, useless type of collection'. Why would anyone
> knowingly ask for this? Is it quicker, use less resourses, or ???
>
> -Paul Randall
Thanks to ekkehard.horner, I found the answer at
http://msdn.microsoft.com/en-us/libr...80(VS.85).aspx. For scripts
posted in a support group, I think I would avoid the 32 flag to make the
collection more user friendly when the user modifies the code to understand
it better.

-Paul Randall


My System SpecsSystem Spec
Reply

Thread Tools



Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46