Debugging .NET-based Windows Services

We haven’t needed to implement a Windows Service in a while, but certainly have experienced the pain of debugging them when run by Service Control Manager (SCM).  Here are a couple of links to good tools and discussion on the topic:

Run Windows Service as a Console Program by Einar Egilsson provides a good example of how to debug your service easily as a console app.  It also includes some good discussion of single- and multi-service hosting services, various ways to end or break out of the service process when running as console app, etc.

Windows Service Helper on CodePlex is a SCM replacement which provides for F5 debugging from Visual Studio. The UI it provides gives you the SCM-esque start, stop, pause capabilities to facilitate debugging the associated functionality in your service.

Hopefully these may be useful to you, but if nothing else, this will be a good reminder for the next time we do a Windows Service.

Get-Sysinternals–Not for Windows Servers

I recently posted about Keeping SysInternals Up-To-Date. Since then I’ve had trouble getting it to work on any of our Windows Server machines.  I couldn’t find much info on this online, so maybe it’ll be helpful to raise the problem here.

There is a problem with Get-Sysinternals.ps1 that prevents it from working on Windows Server platforms.  The problem is due to its dependence on WebClient – the service that provides the ability to treat a URN on the web as a local drive.  The specific line in Get-Sysinternals is:

New-PSDrive -Name SYS -PSProvider filesystem -Root \\\tools

When WebClient is active, this line successfully creates a local drive called SYS that points to \\\tools.  When WebClient is not active, this line causes an error:


New-PSDrive : Drive “\\\tools” does not exist or it’s not a folder.

At …\Get-Sysinternals.ps1:26  char:15

+ New-PSDrive <<<< –Name SYS -PSProvider filesystem -Root \\\tools

     + CategoryInfo : ReadError: (SYS:PSDriveInfo) [New-PSDrive], IOException

     + FullyQualifiedErrorId : DriveRootError, Microsoft.PowerShell.Commands.NewPSDriveCommand

Is the solution to simply turn on the WebClient service?  Unfortunately not.  The official method for installing WebClient is to turn on the Desktop Experience feature. Microsoft does not offer another way (see Installing WebClient Service without Desktop Experience?Desktop Experience also includes (reference Desktop Experience Overview, TechNet): 

  • Windows Media Player
  • Desktop themes
  • Video for Windows (AVI support)
  • Windows SideShow
  • Windows Defender
  • Disk Cleanup
  • Sync Center
  • Sound Recorder
  • Character Map
  • Snipping Tool

Hmmm. We don’t want any of these running on our servers.  Not only do they violate the Least Required Principle, many of them are CPU hogs (Themes, SideShow, Aero), others may execute at unknown times (Disk Cleanup, Sync Center), etc.  Which of these involve installing drivers (Video for Windows?)

No, Desktop Experience is far from appropriate for gaining the functionality of WebClient (which we would only run temporarily anyway).


So, back to the drawing-board.  What are others doing to update SysInternals on Windows Servers?  Is anyone interested to collaborate on adapting the Get-SysInternals script to work for servers?