Use VBScript to Set Local Computer Description

Discussion in 'Scripting' started by Jeremy, May 2, 2009.

  1. Jeremy

    Jeremy Guest

    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 &
    For Each x In Obj
    x.Description = "This is the computer description."

    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
    Jeremy, May 2, 2009
    1. Advertisements

  2. 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?
    Richard Mueller [MVP], May 2, 2009
    1. Advertisements

  3. Jeremy

    Jeremy Guest

    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.
    Jeremy, May 2, 2009
  4. 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)

    Alex K. Angelopoulos, May 3, 2009
  5. 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

    Richard Mueller
    MVP Directory Services
    Hilltop Lab -

    Richard Mueller [MVP], May 3, 2009
  6. Jeremy

    Jeremy Guest

    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

    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

    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

    Jeremy, May 3, 2009
  7. 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?

    Alex K. Angelopoulos, May 3, 2009
  8. 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.
    Alex K. Angelopoulos, May 3, 2009
  9. 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, May 3, 2009
  10. 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, May 3, 2009
  11. Jeremy

    Jeremy Guest

    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.

    Jeremy, May 3, 2009
  12. 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 -

    Richard Mueller [MVP], May 3, 2009
  13. 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.
    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.
    Alex K. Angelopoulos, May 4, 2009
  14. Jeremy

    Jeremy Guest

    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.

    Jeremy, May 4, 2009
  15. 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.

    Alex K. Angelopoulos, May 4, 2009
  16. 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, May 4, 2009
  17. Jeremy

    Jeremy Guest

    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

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

    Alex K. Angelopoulos, May 5, 2009
  19. 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.
    Alex K. Angelopoulos, May 7, 2009
  20. Jeremy

    Jeremy Guest

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

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 (here). After that, you can post your question and our members will help you out.