Install a Windows Service using PowerShell

Visual Studio 2012 removed support for Windows Service installer projects (vdproj) as described by Buck Hodges in this MSDN blog post. My usage of this project type was for installing Windows Services. The experience wasn't satisfying, but rather complicated and ponderous.

Make your life easier by using PowerShell. If you're holding onto Visual Studio 2010 because of an installer project for a Windows service, you might consider using PowerShell.

This script will:

  • initalize a few strings to be used later during installation
  • convert your plaintext password to a secure string
  • create a security credential for the Windows service to be run under
  • check whether the service exists. if so, stop the service, and delete it.
  • install the service
  • optionally start the service

If you experience an error when running this script like The specified service has been marked for deletion, I've found that closing any instances of services.msc has solved that issue.