Use VBScript to 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
 
R

Richard Mueller [MVP]

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


Does it help to specify impersonationLevel and authenticationLevel when you
connect with WMI? For example:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
& strComputer & "\root\cimv2")


Also, when you say you run the script as Administrator, I assume you either
right click the script and select "Run as administrator", or you run a
command prompt by right clicking cmd.exe and selecting "Run as
administrator". Being authenticated to the machine with administrator
credentials no longer will work. Finally, which is line 6?
 
J

Jeremy

I run from a command prompt that I righ-click to run as administrator.
There is no option in the context menu on a .vbs file.

Setting the impersonationLevel=impersonate yields exactle the same result.
I have tried with and without it.

The error Line (line 6 in my error) is x.Put_ .

Thanks for your reply.


Sorry to everyone about the double post.
 
A

Alex K. Angelopoulos

I've tried the demo code and have no trouble at all with it on Vista
Business Edition (32-bit), Win 7 Beta build 7000 x64, or Win2008 Server x64.

Did you try the _modified_ version on the computer, the one that simply sets
the description as you showed? I'm asking because I suspect the error
message could be correct with AD data in some circumstances. Depending on
what you're pulling from where in AD, the value you return may not be a
standard text string.

If you find a generic description can be set successfully, I suggest you
next look at the data you're returning from AD to use as the description. I
would check two things: the typename for the returned value, and then - if
it appears to be a single string - I suggest escaping the data and
displaying it, to check for possible odd characters.

WScript.Echo TypeName(AdDescription)
WScript.Echo Escape(AdDescription)

Jeremy said:
I run from a command prompt that I righ-click to run as administrator.
There is no option in the context menu on a .vbs file.

Setting the impersonationLevel=impersonate yields exactle the same result.
I have tried with and without it.

The error Line (line 6 in my error) is x.Put_ .

Thanks for your reply.


Sorry to everyone about the double post.
 
R

Richard Mueller [MVP]

The description attribute in AD is multi-valued, even though there is never
more than one value. Depending on how you retrieve the value, you could get
an array. For example, ADO either returns a Null if there is no value, or an
array of one string value. TypeName will return "String()" in the later
case.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

Alex K. Angelopoulos said:
I've tried the demo code and have no trouble at all with it on Vista
Business Edition (32-bit), Win 7 Beta build 7000 x64, or Win2008 Server
x64.

Did you try the _modified_ version on the computer, the one that simply
sets the description as you showed? I'm asking because I suspect the error
message could be correct with AD data in some circumstances. Depending on
what you're pulling from where in AD, the value you return may not be a
standard text string.

If you find a generic description can be set successfully, I suggest you
next look at the data you're returning from AD to use as the description.
I would check two things: the typename for the returned value, and then -
if it appears to be a single string - I suggest escaping the data and
displaying it, to check for possible odd characters.

WScript.Echo TypeName(AdDescription)
WScript.Echo Escape(AdDescription)
 
J

Jeremy

I have attempted this as a standalone script entering simply "test" as the
description using the exact code in this post with the same result.

My startup script is extensive and I do many things on the computer with it.
That being said, I take into account all value types returned from AD in my
script(s).

If you were able to run this code on Win2008 x64, it must either be a hotfix
or something else specific to my environment or even the way I am running
it?

Alex, can you step me through the process you use to run the script? Though
I am sure my process for running it is ok, I'm new to Vista/2008 and may be
missing something. I start by putting the script on the desktop. I then
run cmd.exe as administrator by right clicking and choosing to run as
administrator. Then change my directory to the desktop folder where the
..vbs file is located. I then type the name of the file to run it.

Thanks for the help

Alex K. Angelopoulos said:
I've tried the demo code and have no trouble at all with it on Vista
Business Edition (32-bit), Win 7 Beta build 7000 x64, or Win2008 Server
x64.

Did you try the _modified_ version on the computer, the one that simply
sets the description as you showed? I'm asking because I suspect the error
message could be correct with AD data in some circumstances. Depending on
what you're pulling from where in AD, the value you return may not be a
standard text string.

If you find a generic description can be set successfully, I suggest you
next look at the data you're returning from AD to use as the description.
I would check two things: the typename for the returned value, and then -
if it appears to be a single string - I suggest escaping the data and
displaying it, to check for possible odd characters.

WScript.Echo TypeName(AdDescription)
WScript.Echo Escape(AdDescription)
 
A

Alex K. Angelopoulos

You're running it exactly the way I do. What do you mean by same result?
Same result as I get, or the same type mismatch error that you got before?

Jeremy said:
I have attempted this as a standalone script entering simply "test" as the
description using the exact code in this post with the same result.

My startup script is extensive and I do many things on the computer with
it. That being said, I take into account all value types returned from AD
in my script(s).

If you were able to run this code on Win2008 x64, it must either be a
hotfix or something else specific to my environment or even the way I am
running it?

Alex, can you step me through the process you use to run the script?
Though I am sure my process for running it is ok, I'm new to Vista/2008
and may be missing something. I start by putting the script on the
desktop. I then run cmd.exe as administrator by right clicking and
choosing to run as administrator. Then change my directory to the desktop
folder where the .vbs file is located. I then type the name of the file
to run it.

Thanks for the help

Alex K. Angelopoulos said:
I've tried the demo code and have no trouble at all with it on Vista
Business Edition (32-bit), Win 7 Beta build 7000 x64, or Win2008 Server
x64.

Did you try the _modified_ version on the computer, the one that simply
sets the description as you showed? I'm asking because I suspect the
error message could be correct with AD data in some circumstances.
Depending on what you're pulling from where in AD, the value you return
may not be a standard text string.

If you find a generic description can be set successfully, I suggest you
next look at the data you're returning from AD to use as the description.
I would check two things: the typename for the returned value, and then -
if it appears to be a single string - I suggest escaping the data and
displaying it, to check for possible odd characters.

WScript.Echo TypeName(AdDescription)
WScript.Echo Escape(AdDescription)
 
A

Alex K. Angelopoulos

Ignore my previous post. I can confirm that on Vista 32-bit I get the same
error as you do IF the description has already been set to some value:
Error: Value out of range
Code: 8004102B
Source: SWbemObjectEx

So I can confirm it's apparently an issue with doing a put_ in the
environment when a value is already set, and it appears to happen on 32-bit
Vista as well - but not 64-bit Vista or 2008 Server. I've tried running the
test following a reboot and get the same error back.

I initially tried setting some flags on the Put_() method but Vista doesn't
appear to like that. What's weird is the error that we get back; it's not
only undocumented in the Put_ method docs, but when it _has_ been reported
in the past (on XP) it has been a meaningful message - people trying to
create a page file that's too large, for example.

I'm trying to find a way to look inside the problem now.
 
A

Alex K. Angelopoulos

I'm getting nothing useful from trying to explore the Description property.
I _do_ have a workaround for this specific scenario; you can set a
computer's description either locally or remotely by directly going to the
registry value backing it. It works fine using WMI's StdRegProv.
Unfortunately, it doesn't explain why this particular problem happens.

strComputer = "."
Set reg = GetObject("winmgmts:\\"&_
strComputer & "\root\default:StdRegProv")
regpath = "SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters"
value = "New Description for the computer"
returned = reg.SetStringValue( &H80000002, regpath, "srvcomment", value)
WScript.Echo returned ' returned error, which should be 0


Alex K. Angelopoulos said:
Ignore my previous post. I can confirm that on Vista 32-bit I get the same
error as you do IF the description has already been set to some value:
Error: Value out of range
Code: 8004102B
Source: SWbemObjectEx

So I can confirm it's apparently an issue with doing a put_ in the
environment when a value is already set, and it appears to happen on
32-bit Vista as well - but not 64-bit Vista or 2008 Server. I've tried
running the test following a reboot and get the same error back.

I initially tried setting some flags on the Put_() method but Vista
doesn't appear to like that. What's weird is the error that we get back;
it's not only undocumented in the Put_ method docs, but when it _has_ been
reported in the past (on XP) it has been a meaningful message - people
trying to create a page file that's too large, for example.

I'm trying to find a way to look inside the problem now.
 
A

Alex K. Angelopoulos

And one more self-spamming post. ; )

I'm finding the error occurs with the Put_() method against other WMI
properties on Vista x86. I also tried disabling UAC temporarily, and even
enabling the standard administrator account and logging in with it. Same
results. I went on to try using CIM_OperatingSystem instead of
Win32_OperatingSystem, and get the same error value back.

I'm not finding any reports of this specific issue with Vista, however.

Alex K. Angelopoulos said:
Ignore my previous post. I can confirm that on Vista 32-bit I get the same
error as you do IF the description has already been set to some value:
Error: Value out of range
Code: 8004102B
Source: SWbemObjectEx

So I can confirm it's apparently an issue with doing a put_ in the
environment when a value is already set, and it appears to happen on
32-bit Vista as well - but not 64-bit Vista or 2008 Server. I've tried
running the test following a reboot and get the same error back.

I initially tried setting some flags on the Put_() method but Vista
doesn't appear to like that. What's weird is the error that we get back;
it's not only undocumented in the Put_ method docs, but when it _has_ been
reported in the past (on XP) it has been a meaningful message - people
trying to create a page file that's too large, for example.

I'm trying to find a way to look inside the problem now.
 
J

Jeremy

In my case, the only installs we have of Vista and 2008 are x64. I've
pretty much tried what you have with the same error returning. What's
strange is your x64 installs work fine?

If I want to get this thing fixed, do I need to call up Microsoft support?

Thanks for all your help. It's good to know I'm not the only one that can
reproduce the problem.


Alex K. Angelopoulos said:
Ignore my previous post. I can confirm that on Vista 32-bit I get the same
error as you do IF the description has already been set to some value:
Error: Value out of range
Code: 8004102B
Source: SWbemObjectEx

So I can confirm it's apparently an issue with doing a put_ in the
environment when a value is already set, and it appears to happen on
32-bit Vista as well - but not 64-bit Vista or 2008 Server. I've tried
running the test following a reboot and get the same error back.

I initially tried setting some flags on the Put_() method but Vista
doesn't appear to like that. What's weird is the error that we get back;
it's not only undocumented in the Put_ method docs, but when it _has_ been
reported in the past (on XP) it has been a meaningful message - people
trying to create a page file that's too large, for example.

I'm trying to find a way to look inside the problem now.
 
R

Richard Mueller [MVP]

I confirm the problem on 32-bit Vista, but only if there is no existing
value assigned to the property. I tried Put_(0) and Put_(1) to no avail. I
even tried to assign an blank string. I note that the TypeName of the value
is unchanged. It was "String" when there was no value, and the same after a
value was assigned (so it is not an array).

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

Alex K. Angelopoulos said:
And one more self-spamming post. ; )

I'm finding the error occurs with the Put_() method against other WMI
properties on Vista x86. I also tried disabling UAC temporarily, and even
enabling the standard administrator account and logging in with it. Same
results. I went on to try using CIM_OperatingSystem instead of
Win32_OperatingSystem, and get the same error value back.

I'm not finding any reports of this specific issue with Vista, however.
 
A

Alex K. Angelopoulos

Jeremy said:
In my case, the only installs we have of Vista and 2008 are x64. I've
pretty much tried what you have with the same error returning. What's
strange is your x64 installs work fine?

I didn't have a Vista x64 install to work against. Based on your prior
description, I thought you were only encountering the problem on Vista; is
that correct?

At this point it looks to me like a one-version bug (if that's what it is):
I get the problem on Vista, but not XP/2003/2008/Win7 Beta of any bitness.
If I want to get this thing fixed, do I need to call up Microsoft support?

Yes. I think this would be a good point to call Microsoft support; three of
us can see the problem, and haven't found a reason or fix.
Thanks for all your help. It's good to know I'm not the only one that can
reproduce the problem.


Alex K. Angelopoulos said:
Ignore my previous post. I can confirm that on Vista 32-bit I get the
same error as you do IF the description has already been set to some
value:
Error: Value out of range
Code: 8004102B
Source: SWbemObjectEx

So I can confirm it's apparently an issue with doing a put_ in the
environment when a value is already set, and it appears to happen on
32-bit Vista as well - but not 64-bit Vista or 2008 Server. I've tried
running the test following a reboot and get the same error back.

I initially tried setting some flags on the Put_() method but Vista
doesn't appear to like that. What's weird is the error that we get back;
it's not only undocumented in the Put_ method docs, but when it _has_
been reported in the past (on XP) it has been a meaningful message -
people trying to create a page file that's too large, for example.

I'm trying to find a way to look inside the problem now.
 
J

Jeremy

I can reproduce this on both Vista x64 and Server 2008 x64. Any intstall of
those operating systems in our environment is x64 so I have not tested
against x86 versions of the OS.

Thanks again.

Alex K. Angelopoulos said:
Jeremy said:
In my case, the only installs we have of Vista and 2008 are x64. I've
pretty much tried what you have with the same error returning. What's
strange is your x64 installs work fine?

I didn't have a Vista x64 install to work against. Based on your prior
description, I thought you were only encountering the problem on Vista; is
that correct?

At this point it looks to me like a one-version bug (if that's what it
is): I get the problem on Vista, but not XP/2003/2008/Win7 Beta of any
bitness.
If I want to get this thing fixed, do I need to call up Microsoft
support?

Yes. I think this would be a good point to call Microsoft support; three
of us can see the problem, and haven't found a reason or fix.
 
A

Alex K. Angelopoulos

It now sounds to me more likely to be an erratic bug, possibly fixed in
Vista SP1. The primary reason is the failure you get on 2008x64; since I
don't get it, that helps clinch the point that this isn't a consistent
problem at a particular OS level.

I'm now running diagnostics on WMI on my Vista system to see if that changes
anything. I don't have SP1 installed on it either, so I'll try downloading
that for the VM and seeing if we get a cure that way.


Jeremy said:
I can reproduce this on both Vista x64 and Server 2008 x64. Any intstall
of those operating systems in our environment is x64 so I have not tested
against x86 versions of the OS.

Thanks again.

Alex K. Angelopoulos said:
Jeremy said:
In my case, the only installs we have of Vista and 2008 are x64. I've
pretty much tried what you have with the same error returning. What's
strange is your x64 installs work fine?

I didn't have a Vista x64 install to work against. Based on your prior
description, I thought you were only encountering the problem on Vista;
is that correct?

At this point it looks to me like a one-version bug (if that's what it
is): I get the problem on Vista, but not XP/2003/2008/Win7 Beta of any
bitness.
If I want to get this thing fixed, do I need to call up Microsoft
support?

Yes. I think this would be a good point to call Microsoft support; three
of us can see the problem, and haven't found a reason or fix.
 
A

Alex K. Angelopoulos

Wmidiag reported no problems. I've installed SP1 and the Put_() still fails.
Barring any other really good ideas, I'd say this is probably time for the
technical support call.

Alex K. Angelopoulos said:
It now sounds to me more likely to be an erratic bug, possibly fixed in
Vista SP1. The primary reason is the failure you get on 2008x64; since I
don't get it, that helps clinch the point that this isn't a consistent
problem at a particular OS level.

I'm now running diagnostics on WMI on my Vista system to see if that
changes anything. I don't have SP1 installed on it either, so I'll try
downloading that for the VM and seeing if we get a cure that way.
 
J

Jeremy

I have SP1 on all my installs of Vista and 2008 actually. I guess I should
have mentioned that earlier. You're saying that you can replicate it on an
RTM install?

I have an idea I'm going to try, but I have a feeling I'm dealing with a
bug.


Alex K. Angelopoulos said:
It now sounds to me more likely to be an erratic bug, possibly fixed in
Vista SP1. The primary reason is the failure you get on 2008x64; since I
don't get it, that helps clinch the point that this isn't a consistent
problem at a particular OS level.

I'm now running diagnostics on WMI on my Vista system to see if that
changes anything. I don't have SP1 installed on it either, so I'll try
downloading that for the VM and seeing if we get a cure that way.
 
A

Alex K. Angelopoulos

Yes. By the way, my current desktop system - which is Win 7 Beta x64
upgraded from Vista Ultimate x64 - there's no problem whatsoever.

Jeremy said:
I have SP1 on all my installs of Vista and 2008 actually. I guess I
should have mentioned that earlier. You're saying that you can replicate
it on an RTM install?

I have an idea I'm going to try, but I have a feeling I'm dealing with a
bug.


Alex K. Angelopoulos said:
It now sounds to me more likely to be an erratic bug, possibly fixed in
Vista SP1. The primary reason is the failure you get on 2008x64; since I
don't get it, that helps clinch the point that this isn't a consistent
problem at a particular OS level.

I'm now running diagnostics on WMI on my Vista system to see if that
changes anything. I don't have SP1 installed on it either, so I'll try
downloading that for the VM and seeing if we get a cure that way.
 
A

Alex K. Angelopoulos

One more data point. Using a virtual machine with Vista Ultimate RTM freshly
installed, I used similar code to set the description, and it worked the
very first time (as on my other Vista test). Thereafter, Put_ always fails.
I haven't been able to find a confirmed case of the problem occurring on
Vista with integrated SP1 yet, however.
 
J

Jeremy

Short update, seems that it doesn't work in Server 2008 with SP2 which I
just installed on a server either.
 

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