When Microsoft phased out the Windows Server 2003 Resource Kit, many administrators were left scrambling. The traditional approach of using instsrv.exe
and srvany.exe
became obsolete, yet countless legacy applications still need service wrappers. Here's how to handle service installation in Windows Server 2008's new reality.
The modern approach involves using PowerShell or SC (Service Control) commands:
# PowerShell service creation New-Service -Name "MyCustomService" -BinaryPathName "C:\path\to\your\app.exe" -DisplayName "My Service" -StartupType Automatic # Alternative using SC command sc create MyCustomService binPath= "C:\path\to\your\app.exe" DisplayName= "My Service" start= auto
For applications that aren't natively service-aware, NSSM (Non-Sucking Service Manager) has become the de facto replacement:
nssm install MyCustomService nssm set MyCustomService Application "C:\path\to\app.exe" nssm set MyCustomService AppParameters "--config service.conf" nssm set MyCustomService AppDirectory "C:\path\to\app" nssm start MyCustomService
For developers who need more control, here's a minimal C# Windows Service template:
using System.ServiceProcess; public class MyService : ServiceBase { protected override void OnStart(string[] args) { // Your startup logic here } protected override void OnStop() { // Cleanup code } public static void Main() { ServiceBase.Run(new ServiceBase[] { new MyService() }); } }
Compile with Visual Studio or csc.exe
, then install using InstallUtil.exe
from the .NET Framework directory.
For automated deployments, consider this PowerShell function that handles installation and configuration:
function Install-WindowsService { param( [string]$ServiceName, [string]$DisplayName, [string]$BinaryPath, [string]$Description, [string]$StartupType = "Automatic" ) $service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue if ($service) { Stop-Service -Name $ServiceName -Force sc.exe delete $ServiceName } $params = @{ Name = $ServiceName BinaryPathName = $BinaryPath DisplayName = $DisplayName StartupType = $StartupType Description = $Description } $newService = New-Service @params # Configure recovery options sc.exe failure $ServiceName reset= 60 actions= restart/5000 return $newService }
Common issues and their solutions:
- Error 1053: Check application dependencies and PATH variables
- Error 1064: Verify the account has proper privileges
- Service starts then stops: Implement proper logging to capture application errors
Use Event Viewer
> Windows Logs
> Application
for detailed error information.
When working with Windows Server 2008, you'll quickly discover that the traditional Resource Kit tools like instsrv.exe
and srvany.exe
are no longer available. This creates a significant hurdle when you need to run applications as Windows services.
Windows Server 2008 provides several built-in methods for service creation:
Using sc.exe (Service Control)
The Service Control utility comes pre-installed and offers basic service management capabilities:
sc create "MyService" binPath= "C:\path\to\your\executable.exe" start= auto
PowerShell Approach
For more flexibility, PowerShell provides the New-Service
cmdlet:
$serviceParams = @{
Name = "MyPowerShellService"
BinaryPathName = "C:\path\to\your\executable.exe"
DisplayName = "My Custom Service"
StartupType = "Automatic"
Description = "My custom service description"
}
New-Service @serviceParams
The Non-Sucking Service Manager (NSSM) has become the de facto standard for service creation in modern Windows environments:
Basic NSSM Usage
nssm install MyService "C:\path\to\your\executable.exe"
Advanced Configuration Example
nssm install MyService
nssm set MyService Application "C:\path\to\your\executable.exe"
nssm set MyService AppParameters "--verbose --config=C:\config\service.conf"
nssm set MyService AppDirectory "C:\working\directory"
nssm set MyService DisplayName "My Production Service"
nssm set MyService Start SERVICE_AUTO_START
nssm set MyService AppStdout "C:\logs\service.log"
nssm set MyService AppStderr "C:\logs\service_error.log"
For complete control, you can create a native Windows Service using .NET:
using System.ServiceProcess;
public class MyCustomService : ServiceBase
{
public MyCustomService()
{
this.ServiceName = "MyCustomService";
this.CanStop = true;
this.CanPauseAndContinue = false;
this.AutoLog = true;
}
protected override void OnStart(string[] args)
{
// Initialization code here
}
protected override void OnStop()
{
// Cleanup code here
}
public static void Main()
{
ServiceBase.Run(new MyCustomService());
}
}
After building your service, install it using the .NET InstallUtil:
InstallUtil.exe MyCustomService.exe
Or with sc.exe:
sc create "MyCustomService" binPath= "C:\path\to\MyCustomService.exe" start= auto
Key tools for service debugging:
- Event Viewer (eventvwr.msc) for service logs
- Process Explorer to monitor running services
- sc queryex for detailed service status