The ItemIndex thing on Vista is _very_ cool, Andrew. I didn't even know it
existed until your post. That wasn't the problem, but I'm glad you posted
anyway. : )
Jeremy's code works fine on post-Vista systems I tested (2008, Win7 x64
beta), but fails on not only his x64 Vista but also two other 32-bit Vistas
and _his_ x64 Windows 2008 system. I tested the technique using ItemIndex on
my failing Vista box just in case, and it fails there as well with the
usual "out of range" error.
Demo code below. I'm going to try a WMI repository rebuild on my affected
system to see if that may be the issue; the error really _does_ come from
the Put_ line, and you got me thinking that the issue might be WMI truly
trying to report what it thinks is a problem. If there was a common glitch
during repository build, I could see it mucking up and using the wrong
limits when it qualifies a value passed back.
Set Obj =
GetObject("winmgmts:\\.\root\cimv2").InstancesOf(" Win32_OperatingSystem")
set os = Obj.ItemIndex(0)
WScript.Echo os.Description
os.Description = "A New Description"
os.Put_ ' <-- boom! outta range.
"Andrew McLaren" <> wrote in message
news:#...
> "Jeremy" <trombone79atgmail.com> wrote ...
>> The line the error is on may be slightly different than the line of the
>> code I pasted in the post. The error is on the Put_ line.
>
> No; believe me, the error comes from the "Next" line! :-) The word-wrap,
> etc, doesn't matter; what does matter is the *line* in the script, as
> recognised by the VBScript tokenizer. The error message could have said:
>
> First-order syntactic object in script: 6
> Second-order syntactic object in script: 4
>
> ... but that would be pretty obscure and verbose. The 6th "line" in your
> script is indeed "Next". And the error constant WBEM_E_VALUE_OUT_OF_RANGE
> is much more obviously applicable to a Next, than to a Put_.
>
> As I said: if you Google for "Vista and WMI and ItemIndex and
> Win32_OperatingSystem" you might find some more precise info. Here you go:
>
> http://www.microsoft.com/technet/scr...a/indexer.mspx
> http://www.microsoft.com/technet/scr...ista/wmi1.mspx
> http://msdn.microsoft.com/en-us/libr...00(VS.85).aspx
>
> These 3 links will lead you to the answer; which was as I suspected, to
> use ItemIndex. The exact syntax you'll need to use to modify your script
> is, um ... left as an exercise for the reader :-) I don't have time now to
> test it myself, and the experience will help you understand the nature of
> the error message.
>
> Good luck, you're very close to the solution now.
>
> Andrew
> --
> amclar at optusnet dot com dot au
>
>