How to change windows service name after creating it
Solution 1:
@bfhd's answer will work if you just want to change the Display Name (which is what's shown in the list in Services.msc
, but is not the "real" service name (which is the name of the registry key containing the service information, and used in APIs like OpenService
). The Remarks section of this MSDN article talks about service names vs. display names a bit more.
Unfortunately, there's no official way to change a service's name. However, it is probably possible, if you absolutely must rename the service instead of just re-installing it under the new name for some reason. Do the following:
- Stop the service. You will probably confuse the service control manager if you do this on a running service. (You may confuse it anyhow, this is very hacky.)
- Open
regedit.exe
(Registry Editor). - Navigate to
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
and find the subkey with your service's name. - Right-click the key you found in step #3, and select Rename. Enter the new name for the service.
- Restart the computer.
Services.exe
, the process that hosts the service control manager, won't see the change unless you do; attempts to start the renamed process (or otherwise interact with it at all, actually) will fail.
I make no promise of this working. It's probably worth trying, though, if for some reason just reinstalling the service under a new name is so unacceptable.
If you must do this programmatically, there may exist a function RegRenameKey
that can do the fourth step above for you. I stress may exist because, so far as I can tell, this function is completely unofficial; it's not in MSDN and there's precious little info about it. The only thing I found, other than the Windows headers (which have the prototype, and indicate that it's only on Vista - NT6.0 - and newer), is a Sysinternals forum post, which indicates that it calls an NT syscall (also undocumented). The function prototype, from WinReg.h
, is
WINADVAPI
LSTATUS
APIENTRY
RegRenameKey(
_In_ HKEY hKey,
_In_opt_ LPCWSTR lpSubKeyName,
_In_ LPCWSTR lpNewKeyName
);
Solution 2:
The Windows command line program to change services is "sc".
Here's the Microsoft reference page: https://technet.microsoft.com/en-us/library/bb490995.aspx
To change the display name of a service you can run:
sc config "Old service name" displayname= "New service name"
To change the executable you can run:
sc config "Service name" binpath= "C:\path\to\executable\here"
For both of those commands, make sure you have a space between the = and the new name (ie. displayname= "New Name"
, NOT displayname="New Name"
)