Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Install exe as service in Visual Basic .NET 2

Status
Not open for further replies.

UTTech

MIS
Oct 11, 2000
245
US
I am new to programming and Visual Basic .NET so please bear with me.

I am given a project to write an utility which will enable you to install, uninstall, start, and stop an existing application as a service. I figured out how to stop and start the service but cannot figure out how to code to install/uninstall. I know you can do it manually using InstallUtil in DOS (which I was able to do) but I would like to be able to click a button that will install/uninstall the app as a service in VB.NET.

Is there a way to do this?

 
(Copied from the 101 .net samples:)

Create the Windows Service. Simply create a new Windows Service project in Visual Basic. You are provided with a overrides for the OnStart and OnStop methods. Add code to these methods, and implement any additional overrides (such as for the OnContinue and OnPause methods). You must also set the proper parameter. For instance, the CanPauseAndContinue must be set to True for the service to be able to accept those events.

Add an Installer. You can add an installer by right clicking on the design palette of the windows service, and selecting "Add Installer". The installer is required to make the proper changes in the registry, and to get the service hooked into the right event sources. You can then configure the installer. In your ServiceProcessInstaller, you need to determine the account that will start the service. Popular choices are LocalSystem and User. In the WindowsServiceInstaller, you need to specifiy how the service will start. Choose Manual if the service should be started by a user action. Select Automatic if the service should be run on startup.

Create a deployment. Windows Services can be deployed by using the InstallUtil.exe utility that comes with the .NET Framework. However, a more convenient method is to use a deployment project to create an MSI file. This is only slightly tricky for a Windows Service. First, add a deployment project to the solution containing the service project. Then create a Custom Action for the primary output of the Windows Service project. (To do this, right-click on the deployment project name and select View -> Custom Actions. Then right click on the Custom Actions and select Add Custom Action. When the dialog box opens double click the Application folder and select the primary output from your Windows Service project. It will add this custom action to all four installer actions: Install, Commit, Rollback and Uninstall.) You can now Build your solution, and the resulting MSI file will install the Windows Service

The gap between theory and practice is not as wide in theory as it is in practice.
 
Thank you for your response.

The program I am trying to install as a service is already written in XBase++. It is already written so it can be converted into a service. Can this be done without rewriting the program?
 
I have no clue about XBase++, but I guess writing a .net class with routines what to do on start, stop etc. These routines would kick of or kill your XBase++ program. I guess that would do the trick

The gap between theory and practice is not as wide in theory as it is in practice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top