Troubleshooting SC.EXE Service Creation for SVNServe on Windows: Fixing “binpath” Syntax Issues


2 views

When attempting to create Windows services using sc.exe, particularly for applications with installation paths containing spaces, you'll often encounter syntax challenges. The Subversion case is particularly tricky because:

# This common approach fails:
sc create svnserve binpath="C:\Program Files (x86)\Subversion\bin\svnserve.exe" --service

Windows requires specific escaping for paths containing spaces when using SC.EXE. Here's the correct format:

# Working solution for SVNServe:
sc create svnserve binpath="\"C:\Program Files (x86)\Subversion\bin\svnserve.exe\" --service --root C:\SVNRoot" displayname="Subversion" depend=tcpip start=auto obj="NT AUTHORITY\LocalService"

1. Double quotes within double quotes: Notice the escaped inner quotes (\"...\")
2. Parameter ordering: The binpath must come before other parameters
3. Service arguments: All arguments must be included within the binpath quotes

For more complex service configurations, consider PowerShell's New-Service:

$svcParams = @{
    Name = "svnserve"
    BinaryPathName = '"C:\Program Files (x86)\Subversion\bin\svnserve.exe" --service --root C:\SVNRoot'
    DisplayName = "Subversion"
    StartupType = "Automatic"
    Credential = "NT AUTHORITY\LocalService"
}
New-Service @svcParams

After creation, always verify:

# Check service status
sc query svnserve

# Test starting the service
sc start svnserve

# View detailed configuration
sc qc svnserve

If the service still fails:

  1. Run the executable directly from command prompt to test arguments
  2. Check Windows Event Viewer for service-specific errors
  3. Verify the service account has appropriate permissions

Many developers encounter this frustrating scenario when trying to create Windows services using paths containing spaces. The fundamental issue lies in how sc.exe processes quotes within the binpath parameter.


sc create svnserve binpath="\"C:\Program Files (x86)\Subversion\bin\svnserve.exe\" --service --root C:\SVNRoot" displayname="Subversion" depend=tcpip start=auto obj="NT AUTHORITY\LocalService"

This seemingly correct command triggers the SC.EXE usage help instead of creating the service. The root cause is the complex nested quotation requirement when paths contain spaces.

After extensive testing, I've found these reliable patterns for service creation:


# Method 1: Triple escaping (works in cmd.exe)
sc create MyService binpath= "\"\"C:\Path With Spaces\app.exe\" -args\"" start= auto

# Method 2: Using caret escapes (recommended for batch files)
sc create MyService binpath= ^""C:\Path With Spaces\app.exe" -args^" start= auto

# Method 3: The cleanest PowerShell approach
& sc.exe create MyService binpath= '"C:\Path With Spaces\app.exe" -args' start= auto

Here's the fixed version of the original SVN service command:


sc create svnserve binpath= ^""C:\Program Files (x86)\Subversion\bin\svnserve.exe" --service --root C:\SVNRoot^" displayname= "Subversion" depend= tcpip start= auto obj= "NT AUTHORITY\LocalService"

If the quoting madness becomes unbearable, consider these alternatives:


# Option 1: Use the short path name (8.3 format)
sc create svnserve binpath= "C:\PROGRA~2\Subversion\bin\svnserve.exe --service --root C:\SVNRoot" displayname= "Subversion"

# Option 2: PowerShell's New-Service cmdlet
New-Service -Name "Subversion" -BinaryPathName '"C:\Program Files (x86)\Subversion\bin\svnserve.exe" --service --root C:\SVNRoot' -DisplayName "Subversion" -StartupType Automatic -Credential "NT AUTHORITY\LocalService" -DependsOn "tcpip"
  • Check the system event log for detailed SC.EXE errors
  • Try the command in a clean cmd.exe session (not from IDE terminals)
  • Verify the service account has proper permissions on the executable
  • Test with a simple path first, then add complexity