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.


Discussion is closed.

Feedback usabilla icon