Set Local Computer Description

J

Jeremy

I have been doing this for years in XP and Server 2003, but recently I have
been installing Vista x64 Edition for some specific needs. This code is
part of a workstation startup script that pulls the description from AD and
makes it the local description on the computer. This does not work in Vista
x64 or Server 2008 x64 and I have found no explanation on the Internet as of
yet. I have not tested in x86 installs of the same OS. Yes, I am running
it as administrator while testing, if I do not, I receive Access Denied.


sComputer = "."
Set Obj = GetObject("winmgmts:\\" & sComputer &
"\root\cimv2").InstancesOf("Win32_OperatingSystem")
For Each x In Obj
x.Description = "This is the computer description."
x.Put_
Next


The object is being created just fine. I can use other methods on the
object successfully like GetText_ . I have found no documentation that says
Put_ shouldn't work.
Any help would be appreciated. This one is driving me crazy.

When running, I receive the following error:
---------------------------
Windows Script Host
---------------------------
Script: C:\Users\username\Desktop\test.vbs
Line: 6
Char: 4
Error: Value out of range
Code: 8004102B
Source: SWbemObjectEx
 
A

Andrew McLaren

Hi Jeremy,

I dunno the exact answer, but this issue does ring a bell ...

Note that the WSH error message reports WBEM_E_VALUE_OUT_OF_RANGE for *Line
6* of your script. So the problem is not with the Put_ method; it's on the
*Next* statement.

Win32_OperatingSystem returns a collection, which has always been a bit
weird because you can only have one OS instance at a time on a given
machine. I seem to recall - from some previous case in the last 3 years -
that on Vista, you now need to explicitly handle WMI collections which have
a cardinality of one, by using an "ItemIndex" property (eg
obj.<prop>.ItemIndex(0), to identify the first, and only, member of the
collection). Prior to Vista, WMI was less strict about this; so your
existing syntax should work okay on XP or 2003.

If you Google for "Vista and WMI and ItemIndex and Win32_OperatingSystem"
you might find some more precise info.

Hope this helps a bit,

Andrew
 
J

Jon

Jeremy said:
I have been doing this for years in XP and Server 2003, but recently I have
been installing Vista x64 Edition for some specific needs. This code is
part of a workstation startup script that pulls the description from AD
and
makes it the local description on the computer. This does not work in
Vista
x64 or Server 2008 x64 and I have found no explanation on the Internet as
of
yet. I have not tested in x86 installs of the same OS. Yes, I am running
it as administrator while testing, if I do not, I receive Access Denied.


sComputer = "."
Set Obj = GetObject("winmgmts:\\" & sComputer &
"\root\cimv2").InstancesOf("Win32_OperatingSystem")
For Each x In Obj
x.Description = "This is the computer description."
x.Put_
Next


The object is being created just fine. I can use other methods on the
object successfully like GetText_ . I have found no documentation that
says
Put_ shouldn't work.
Any help would be appreciated. This one is driving me crazy.

When running, I receive the following error:
---------------------------
Windows Script Host
---------------------------
Script: C:\Users\username\Desktop\test.vbs
Line: 6
Char: 4
Error: Value out of range
Code: 8004102B
Source: SWbemObjectEx




You could set it using the following command (run elevated).....

net config server /SRVCOMMENT:"My description"

which could be integrated into a VBScript.



Possibly a bug with WMI. The same error occurs with Powershell.....

PS (1) > gwmi Win32_OperatingSystem | foreach
{$_.Description="whatever";$_.Put()}
Exception calling "Put" with "0" argument(s): "Exception calling "Put" with
"0" argument(
s): "Value out of range ""
At line:1 char:71
+ gwmi Win32_OperatingSystem | foreach {$_.Description="whatever";$_.Put(
<<<< )}

and also using the 'wmic' command .....

PS (2) > wmic os set description="TryAgain"
Updating property(s) of '\\JONV\ROOT\CIMV2:Win32_OperatingSystem=@'
ERROR:
Code = 0x8004102b
Description = Value out of range
Facility = WMI


so the error isn't VBScript specific.
 
J

Jeremy

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.
 
A

Andrew McLaren

Jeremy said:
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/scriptcenter/topics/vista/indexer.mspx
http://www.microsoft.com/technet/scriptcenter/topics/vista/wmi1.mspx
http://msdn.microsoft.com/en-us/library/aa826600(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
 
A

Alex K. Angelopoulos

We're having a long party in the other thread about this topic. Thanks for
the non-VBScript confirmation. : )

I think Jeremy was trying to avoid "net config" due to the lack of remote
usability. There's also an issue with "net config" disabling the LAN Manager
Service's autotuning. : (
 
J

Jon

Alex K. Angelopoulos said:
We're having a long party in the other thread about this topic. Thanks for
the non-VBScript confirmation. : )

I think Jeremy was trying to avoid "net config" due to the lack of remote
usability. There's also an issue with "net config" disabling the LAN
Manager Service's autotuning. : (



You're welcome. I'm glad someone read it. I was beginning to think it had
been overlooked. ;-)

That's interesting about autotuning. Wasn't aware of the side effects of the
'net config' command.Your registry solution with 'srvcomment' at

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters

looked like it could potentially work if it were also combined with a
suitable 'refresh' ie a reboot or perhaps a stop / start of the 'Server' /
'Browser' services (??) I was thinking along similar lines using
'WshShell.RegWrite', but was too lazy to test out the 'reboot theory'.

Anyhow hope the party has a happy ending :)
 
A

Alex K. Angelopoulos

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.
 
R

Richard Mueller [MVP]

I also tried ItemIndex on my 32-bit Vista machine with the same result
(value out of range error). I used slightly different code:

strComputer = "West01"
Set colOSs = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
& strComputer & "\root\cimv2").InstancesOf("Win32_OperatingSystem")
colOSs.ItemIndex(0).Description = "Test Lab"
colOSs.ItemIndex(0).Put_
 
J

Jeremy

Thanks all for helping out. I'm leaning towards a problem with WMI in
Vista, but a call to MS will determine that one way or the other.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top