How Can I Change the Description for a Computer?

Hey, Scripting Guy! Question

Hey, Scripting Guy! When I use Windows Explorer to connect to a remote computer, I can see a description of that computer in the Details pane. How can I change the description for a computer?

-- GF

SpacerHey, Scripting Guy! AnswerScript Center

Hey, GF. Just to make sure everyone is clear what we’re talking about, we are not talking about the Description attribute in Active Directory; instead, we’re talking about the computer description that gets broadcast across the network. (If you’d rather know how to change the Description attribute in Active Directory, see this Hey, Scripting Guy! column.)

For example, in Windows XP you can get to the computer description by right-clicking My Computer, clicking Properties, and then looking on the Computer Name tab in the System Properties dialog box:

Computer Description

And, as you noted, if you connect to this computer using Windows Explorer, the description will appear in the Details pane as well:

Computer Description

We thought it was pretty exciting, too.

So how can you change the description for a computer? Well, you could open up Regedit.exe and manually change the registry value HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\lanmanserver\parameters\srvcomment. Or, you could just run a script like this one:

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."

Set objRegistry = GetObject _
("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = "System\CurrentControlSet\Services\lanmanserver\parameters"
strValueName = "srvcomment"
strDescription = "Description changed programmatically"

objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strDescription

Of course it’s easy; after all this time did you really think we’d suddenly start giving you complicated and convoluted answers to your questions? We begin by defining a constant named HKEY_LOCAL_MACHINE and setting the value to &H80000002; in a minute we’ll use this constant to tell the script which registry hive we want to work with. We then connect to the WMI service (in this case on the local computer, though we can just as easily modify the registry on a remote machine) and bind to the StdRegProv class. (Which, as we never tire of telling people, happens to be found in the root\default namespace.)

Next we assign values to three variables:

strKeyPath = "System\CurrentControlSet\Services\lanmanserver\parameters"
strValueName = "srvcomment"
strDescription = "Description changed programmtically"

The variable strKeyPath represents the path within the HKEY_LOCAL_MACHINE portion of the registry; strValueName represents the registry value (srvcomment) we’re about to change; and strDescription - that’s right: strDescription represents the new computer description. That’s a very astute observation.

Note. We’d tell you that you guys are way better at this stuff than we are, but we don’t want our manager to get any ideas. And yes: getting an idea would be a first for a Microsoft manager!

All we have to do now is call the SetStringValue method, passing HKEY_LOCAL_MACHINE and our three variables as the method parameters:

objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strDescription

Scripts like that really do make life worth living, don’t they?

Note. Be forewarned that even though this change is made in the registry the new description might not take effect until the computer has rebooted. Just something to keep in mind.

Comments (11)

  1. jrv says:

    I am not so sure why everyone makes this so hard.  WMIC does this in one short line.  It can be put into almoat any kind of script.

    WMIC /node:w8test os set description='My new descritpion'

    That's it.  No registry stuff to play with.

  2. Evan Sullivan says:

    How would I adapt this to change it on a remote computer?  I would have full domain admin rights on the PC running the script.

  3. Henry Ferlauto says:

    How would set strDescription to an environment variable?  

    For example set the description to the value of %username%

  4. Robert says:

    Use psexec to run it on a remote computer.

  5. Montgomery Burns says:

    Manually changing the registry value is a lot easier.  How do you even run scripts?

  6. Ed Wilson says:

    @Montgomery Burns, yes, this is an old VBScript written more than 7 years ago. This is MUCH easier to do in Windows PowerShell as far as how to run the script I have a FAQ on the Script center here…/dd940113

  7. Keith Pratt says:

    Here is a batch file I made for doing this.  Prompts for the name and description in the command window and then asks if you want to do more machines at the end. Just copy and paste into a text file and save as .bat


    set /p "machinename=Enter the name of the Machine:"

    set /p "description=Enter the Description:"

    sc \%machinename% start RemoteRegistry

    ping %machinename%

    reg add \%machinename%HKEY_LOCAL_MACHINESYSTEMCurrentControlSetservicesLanmanServerParameters /v "srvcomment" /t REG_SZ /d "%description%" /f

    sc \%machinename% stop RemoteRegistry

    set /p "goagain=Do you want to change another machine?(Y/N)"

    If "%goagain%"=="y" goto start

    If "%goagain%"=="Y" goto start

    If "%goagain%"=="yes" goto start

    If "%goagain%"=="YES" goto start

  8. terry says:

    or you could just use REG.exe: REG ADD HKLMSYSTEMCurrentControlSetservicesLanmanServerParameters /v srvcomment /t REG_SZ /d "your description here" /f

  9. Russ S says:

    I want to thank  Keith Pratt  for hi 22 Mar 2013 8:18 AM post.

    I just used your script to change descriptions on 15 computers. I worked extremely well.

  10. TechyGeeksHome says:

    We had a similar issue where we needed to change 100’s of remote computer descriptions, so we created this tool: It allows you to local or remote connect to a computer
    on a network (run it with admin rights!) and gather and change the description immediately without requirement for reboot etc. Hope it helps.

  11. RA says:

    Thank you, Keith Pratt

Skip to main content