Many developers first attempt to rename Windows services by modifying HKLM\SYSTEM\CurrentControlSet\Services
registry entries. While this stores service configuration, directly editing these values often breaks service functionality because:
- Service binaries reference the original name internally
- SCM (Service Control Manager) maintains cached metadata
- Dependencies might reference the old service name
Microsoft's documentation explicitly states that service names are immutable after installation. The only supported methods are:
- Uninstall and reinstall with new name
- Create a service wrapper
Here's a complete workflow to properly "rename" a service by creating a new instance:
# 1. Export current service configuration
$service = Get-WmiObject -Class Win32_Service -Filter "Name='OldServiceName'"
$service | Export-Clixml -Path "C:\temp\OldServiceConfig.xml"
# 2. Create new service with desired name
New-Service -Name "NewServiceName"
-BinaryPathName $service.PathName
-DisplayName "New Display Name"
-StartupType $service.StartMode
-Credential (Get-Credential)
# 3. Copy any registry parameters
Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\OldServiceName" |
ForEach-Object {
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\NewServiceName"
-Name $_.PSChildName
-Value $_.$($_.PSChildName)
}
# 4. Verify and clean up
Start-Service "NewServiceName"
Stop-Service "OldServiceName" -Force
sc.exe delete "OldServiceName"
For complex services that can't be easily reinstalled, create a proxy DLL using C++:
// service_wrapper.cpp
#include <Windows.h>
#include <stdio.h>
SERVICE_STATUS_HANDLE hStatus;
void WINAPI ServiceMain(DWORD argc, LPTSTR* argv) {
// Forward all calls to original service
SC_HANDLE scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
SC_HANDLE svc = OpenService(scm, "OriginalServiceName", SERVICE_ALL_ACCESS);
// Implement service control handlers here...
}
int main() {
SERVICE_TABLE_ENTRY ServiceTable[] = {
{ "NewServiceName", ServiceMain },
{ NULL, NULL }
};
StartServiceCtrlDispatcher(ServiceTable);
return 0;
}
- Update all service references in scheduled tasks, scripts, and monitoring tools
- Service SID (Security Identifier) will change with the new name
- Consider using Group Policy Preferences for enterprise-wide updates
When working with Windows Services, many developers encounter a frustrating limitation - the service's actual name (stored in the registry) appears immutable through standard UI tools. While changing the display name is straightforward via Service Control Manager, modifying the underlying service name requires deeper system manipulation.
The service name is stored under HKLM\SYSTEM\CurrentControlSet\Services
. Direct registry editing is possible but risky:
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\OldServiceName] "DisplayName"="New Display Name"
However, simply renaming the registry key won't work - Windows references services by their original names in multiple locations.
The safest method involves creating a new service with the desired name and deleting the old one:
:: Export current service configuration sc queryex OldServiceName > service_config.txt :: Create new service with identical parameters sc create NewServiceName binPath= "C:\path\to\executable.exe" start= auto displayname= "New Display Name" :: Verify new service sc start NewServiceName sc query NewServiceName :: When confirmed working, delete old service sc delete OldServiceName
For more control, use PowerShell to copy all service properties:
$service = Get-WmiObject -Class Win32_Service -Filter "Name='OldServiceName'" $newService = Invoke-WmiMethod -Class Win32_Service -Name Create -ArgumentList @( $null, $service.PathName, $service.ServiceType, $service.StartMode, $service.ErrorControl, "NewServiceName", $null, $null, $null, $null, $null, $service.DisplayName ) if ($newService.ReturnValue -eq 0) { Stop-Service -Name OldServiceName & sc delete OldServiceName }
- Always backup the registry before making changes
- Update any scripts or applications referencing the old service name
- Service dependencies may need reconfiguration
- The service binary path remains unchanged - only the registration changes
For services installed via installers (like .msi packages), consider:
msiexec /x {ProductCode} /qn msiexec /i Installer.msi SERVICENAME=NewServiceName /qn