ENTERPRISE

Programming Windows Services with Microsoft Visual Basic 2008 : Installing Services

11/27/2012 6:55:26 PM
Although you can easily create batch files to install a service, at times you might want to carry out more sophisticated actions than a batch file allows.

Microsoft Visual Studio 2008 provides you with the ability to create a setup project by either using the setup project template or by using the setup project wizard. 

Adding the Setup Project

The first thing we need to do is create the setup project. Open your tutorials solution. Right-click the solution, choose Add, and then select New Project. From the Project Template dialog box, expand Other Project Types, select Setup And Deployment, and then select Setup Project.

Select the Setup Project, not the Setup Wizard. I have left my setup project named setup1. After we add the setup project to the solution, we need to configure it.

Add the Project Output

Right-click the setup1 project, select Add, select Project Output, and then select Primary Output. Click OK. This will add the exe and dependencies of your service.

Note

If you are in the debug configuration, the output will be from the debug folder; if you are in the release, it will be from the release folder.


Now we need to create a custom action that will install the service.

Creating Custom Actions

Custom actions define how and what a setup program does. For our project, we need to install the service and the debug symbols. Your service may have other things to include, such as resource files, bitmaps, or configuration files.

Creating a Service Custom Action

First, we want to create the output that will build and install the service. Right-click the setup1 project again, and this time choose View and then choose Custom Actions. Click OK. Right-click Custom Actions. From the pop-up menu, select Add Custom Action. Select Application Folder and then click OK. Select Primary Output From Tutorials (Active) and click OK.

Creating a Debug Symbol Custom Action

Next, we want to add debug symbols. Right-click the setup1 project, select Add, and then select Project Output. Select Debug Symbols and click OK. Now the service and the debug symbols are ready to be installed.

Adding a Configuration File

Right-click the setup1 project again, choose Add, and then choose File. Browse to where your configurations file is, select it, and click OK. You will notice that the file is now added to your project. Right-click the file and choose Properties, or double-click to open the file for editing. In the Properties window, you can change the output target name, location, and several other important attributes of the file when it is installed on the user or server computer.

Testing the Setup Project

To test the project, right-click the setup1 project and choose Build. By default, the setup project will not build each time you build the solution.

After you build the setup program, open Windows Explorer and browse to the generated setup1.msi file, right-click it, and select Install from the pop-up menu. The service will now be installed. You can verify installation by going to the Services window and verifying that you see the service listed. If you want to uninstall the service, you can use Add/Remove Programs or go back to your msi package, right-click it, and select Uninstall.

Note

If you need custom security settings or other things included with your project, review the MSDN documentation for creating setup projects.

Other  
 
Most View
Windows 8 : Diagnosis and Recovery - Refresh and Reset
Share Photos From Your Android Phone
Nvidia Quadro K5000 Professional Graphics Card (Part 3)
How To Buy The Perfect Gear (Part 2) - Cameras buying guide
Microsoft Surface Pro - The New Windows Tablet
Panasonic Lumix DMC-FZ62 - Solid Upgrade Of Last Year's FZ48 Model
Troubleshooting Reference – May 2013 (Part 1)
Livescribe Sky - Sync Your Handwritten Notes
DirectX 10 Game Programming : Shaders and Effects - Geometry Shaders
Migrating Your Mac
Top 10
Windows 7 : Programming Multiple I/O Queues and Programming I/O - WatchDog Timer: Self-Managed I/O
Windows 7 : Programming Multiple I/O Queues and Programming I/O - Reading and Writing the Registry
Windows 7 : Programming Multiple I/O Queues and Programming I/O - Retrieving Requests from a Manual Queue
Windows 7 : Programming Multiple I/O Queues and Programming I/O - Handling Requests from a Parallel Queue
Windows 7 : Programming Multiple I/O Queues and Programming I/O - Creating and Configuring the Queues (part 2)
Windows 7 : Programming Multiple I/O Queues and Programming I/O - Creating and Configuring the Queues (part 1)
Windows Server 2012 : Planning, implementing, and managing Group Policy (part 9) - Configuring WMI filtering
Windows Server 2012 : Planning, implementing, and managing Group Policy (part 8) - Managing GPO links, Configuring security filtering
Windows Server 2012 : Planning, implementing, and managing Group Policy (part 7) - Viewing infrastructure status, Creating GPOs
Windows Server 2012 : Planning, implementing, and managing Group Policy (part 6) - Advanced Audit Policy Configuration