How Can I Change a Service Description?

ScriptingGuy1

Hey, Scripting Guy! Question

Hey, Scripting Guy! How can I change a service description?

— DD

SpacerHey, Scripting Guy! AnswerScript Center

Hey, DD. Well, we hope you’re happy, DD. Now the Scripting Guy who writes this column will never be able to sleep again – and it’s all your fault!

Sure, we’ll explain what we mean by that; after all, now that we are no longer able to sleep we have plenty of time for stuff like that. Many years ago the Scripting Guy who writes this column saw a movie about some boogeyman-like character. The premise of the movie was that this boogeyman existed only as long as people believed in him; if people stopped believing in him he’d disappear forever.

Of course, most people went about their daily lives without ever giving the boogeyman a single thought; needless to say, that’s not a very good thing if you happen to be a boogeyman who will disappear if people stop believing in you. Therefore this boogeyman (and, yes, we suppose we should call it a boogeyperson) started a sort of public relations campaign to get people to believe in him. And once people started believing in him, well ….

Oh, and for some reason the boogeyman has to wait for people to fall asleep so he can enter the world through their dreams and then kill the unsuspecting sleeper (which is the sort of thing that boogeypeople tend to do). To tell you the truth, the Scripting Guy who writes this column was never really sure how this enter-the-world-through-someone’s-dreams thing worked. But, then again, he was never really sure how a boogeyman who allegedly could enter the real world only through someone’s dreams somehow managed to enter the real world and start a public relations campaign, either.

And no, we don’t believe this movie did win an Academy Award for Best Picture. In fact, there’s a chance it was never even nominated for such an award. Go figure.

Anyway, the point is this: once your beliefs change you don’t dare fall asleep; do that and the boogeyman is likely to come and get you. Which means that, thanks to this question about service descriptions, the Scripting Guy who writes this column doesn’t dare fall asleep ever again.

Note. Admittedly, that doesn’t make any sense. But, then again, the fact that things don’t make any sense is how you separate the real Hey, Scripting Guy! columns from their cheap imitations.

As it turns out, the Scripting Guy who writes this column used to go about his daily life without ever thinking about changing the description of a service. After all, why would he think about something like that; considering the fact that you can change service start modes and service passwords and service thises and thats, well, how hard could it be to change a service description? But then he read your question and – foolishly – opened up the WMI SDK to get the exact syntax for changing a service description.

Much to his surprise, there is no WMI method for changing the description of the service. (Hear that ominous music in the background?) The Scripting Guy who writes this column always believed that you could change a service description using a script, but he was wrong. So now he can never go to sleep again, lest the boogeyman come.

On the other hand, if all the boogeyman wants is a script that can change the description of a service, well, he can use this one:

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = “.”

Set objRegistry = GetObject(“winmgmts:\\” & strComputer & “\root\default:StdRegProv”)

strKeyPath = “System\CurrentControlSet\Services\SerialKeys” strValueName = “Description” strValue = “This is the SerialKeys service.”

objRegistry.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

And no, you’re not dreaming. The Scripting Guy who writes this column was correct: WMI doesn’t provide a straightforward method for changing the description of a service. But that doesn’t mean that you can’t change the description of a service; it just means that you have to use a script that goes out and changes the description in the registry. Like this one does.

So how does this script go out and change the description in the registry? Well, to begin with, it defines a constant named HKEY_LOCAL_MACHINE and sets the value to &H80000002; this tells the script which registry hive to work with. The script then connects to the WMI service on the local computer and, in particular, to the root\default namespace and the StdRegProv class.

Note. Sure, you can use this script to change the description of a service on a remote computer. To do that, just assign the name of the remote machine to the variable strComputer.

After connecting to the WMI service we then assign values to three variables:

strKeyPath, which represents the path (within HKEY_LOCAL_MACHINE) to the registry key for the service we want to modify. This value should be set to System\CurrentControlSet\Services\ plus the name of the service. Thus: System\CurrentControlSet\Services\SerialKeys.

strValueName, the name of the registry value to be modified. As you might expect, with this script that happens to be Description.

strValue, which holds the new description for the service.

After assigning values to those variables all we have to do is pass the variable names and the constant HKEY_LOCAL_MACHINE to the SetStringValue method and we’re done:

objRegistry.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

If you now open the Services console you’ll see a new description for the SerialKeys service. Kind of eerie to even think about, isn’t it?

Incidentally, we hope none of you are worried about the health of the Scripting Guy who writes this column; the truth is, he should be able to fall asleep again without any problem. In fact, as near as we can tell he must have dozed off two or three times just trying to finish this column.

0 comments

Discussion is closed.

Feedback usabilla icon