2

First to say, I normally install my windows service in visual studio command prompt 2010 with InstallUtil command.

Is it possible to install my windows service directly from visual studio by Start Debugging (F5)?

I tryed to start cmd.exe in my windows service project Properties, under Debug tab:

Start external program: C:\Windows\System32\cmd.exe

Command line arguments: /k "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 (with this InstallUtil is enabled as command in cmd)

With that cmd will open. I would like that when cmd is run it automaticly executes:

InstallUtil MyServiceName

(when cmd starts it is already in my Debug folder where myservice.exe is)

Is that possible somehow?

Community
  • 1
  • 1
Korvus
  • 31
  • 1
  • 5
  • I managed it somehow. To the **Command line arguments** needs to be added: **& InstallUtil HostingWindowsService.exe** which will execute after first part (before **&**) and therefore "speaks" cmd language. Now I have automated installation of the service, but to uninstall one I still need to type into that cmd window **sc delete myServiceName**. – Korvus Sep 05 '13 at 15:47
  • I can't answer my question for 8 hours so I'll temporary write it here: **Start external program:** _C:\Windows\System32\cmd.exe_ (your path to cmd.exe) **Command line arguments** _/k "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 & sc delete MyServiceName & InstallUtil MyServiceFileName.exe & Exit_ (don't forget to change path to yours) – Korvus Sep 05 '13 at 16:20
  • _MyServiceName_ is value of ServiceName property of serviceInstaller from ProjectInstaller.cs (generated by VS) _MyServiceFileName_ is name of compiled *.exe file in your Debug folder. Probably same as name of project. – Korvus Sep 05 '13 at 16:22

1 Answers1

1

Here is complete solution.

What

Installing windows service automatically from Visual Studio when Start Debugging (F5) without adding any installing code to the project (except project installer you need to register windows service at all).

Visual Studio 2010 project properties

Right click your service project and choose properties. Go to Debug section. Input this:

Start external program: C:\Windows\System32\cmd.exe (your path to cmd.exe)

Command line arguments: /k "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 & sc delete MyServiceName & InstallUtil MyServiceFileName.exe & Exit (don't forget to change path to yours)

MyServiceName is value of ServiceName property of serviceInstaller from ProjectInstaller.cs (generated by VS)

MyServiceFileName is name of compiled *.exe file in your Debug folder. Probably same as name of project.

What that did?

We started command prompt that uses powers of visual studio command prompt (we need InstallUtil), deleted old instance of service if it exists, and install new one (and starts it if it's StartType is Automatic)

If you need...

Debugging

Visual Studio 2010. Go to Debug / Attach to proccess. Mark Show processes from all users and Show processes from all session to be able to see your windows services. Name of the process will be your MyServiceFileName. Processes must be attached manually every time you want to debug them. Ofcourse, service must be started to be visible and debugable.

To create the installers for your service (MSDN)

To see how to create installer for your windows service go to this link:

http://msdn.microsoft.com/en-us/library/zt39148a%28v=vs.100%29.aspx

Community
  • 1
  • 1
Korvus
  • 31
  • 1
  • 5