views:

418

answers:

1

I've been following a tutorial on http://michaelellerbeck.com/2009/01/12/creating-a-service-for-visual-basic-2008-express/ for creating a service using VB Express 2008. I got the first part working and managed to get the sample to install using InstallUtil, but the second part has you use a form with buttons to install and uninstall the service.

I'm wondering if there are instructions for installing the service from a command line so I could just change to a specific subdirectory and type "myservice /i" to install it or /u to uninstall it.

Any advice or tutorials to do this?

A: 

In the example you have provided, the code that installs the service using the undocumented call:

Try
    System.Configuration.Install.ManagedInstallerClass.InstallHelper(New String() {”C:\Test\YourService1.exe”})
Catch ex As Exception
    MessageBox.Show(ex.ToString)
End Try

is placed in an event handler under a button. Well, there's nothing preventing you from executing this code directly.

To do that, just create a console application, and paste the code above into the entry point, Sub Main(). Then, create your executable.

Robert Harvey