You can also debug your service installation code. To demonstrate one way of doing this, I've added some custom code to the ProjectInstaller.vb class that updates ServiceAdmin 's description as shown in the Description column of the Services applet. Thanks to what looks like a bug in the Framework class library, there's no way of specifying your service's description. If you try using the ServiceProcessDescription attribute, it just overwrites what's displayed in the Name column. To overcome this, the code in Listing 10-2 overrides the project installer's Install virtual method, performs the actual installation, and then opens the appropriate registry key and hacks the service description manually. Although this code isn't very elegant, it does the job and serves as a way of looking at the debugging of installation code.
Imports Microsoft.Win32 <RunInstaller(True)> Public Class ProjectInstaller Inherits System.Configuration.Install.Installer 'Wizard-generated installer code omitted for the sake of brevity Public Overrides Sub Install(ByVal stateSaver As Collections.IDictionary) 'First do the install MyBase.Install(stateSaver) 'System.Diagnostics.Debugger.Launch() 'Navigate to the correct registry key Dim SystemKey As RegistryKey = Registry.LocalMachine.OpenSubKey("System") Dim ControlSetKey As RegistryKey = _ SystemKey.OpenSubKey("CurrentControlSet") Dim ServicesKey As RegistryKey = ControlSetKey.OpenSubKey("Services") Dim ServiceKey As RegistryKey = _ ServicesKey.OpenSubKey(Me.ServiceInstaller1.ServiceName, True) 'Now we can set the service description ServiceKey.SetValue("Description", "Allows remote service administration") 'Cleanup ServiceKey.Close() ServicesKey.Close() ControlSetKey.Close() SystemKey.Close() End Sub End Class
Before you run installutil.exe, open the ServiceAdmin solution and remove the comment mark from the following line of code after the call to MyBase.Install(stateSaver) shown in Listing 10-2:
When you actually install the service, this line of code launches the CLR's JIT debug dialog window. From this dialog window, select to debug using the instance of Visual Studio that contains the ServiceAdmin solution. From the next dialog window, choose to debug only .NET code by deselecting the native code option. At this point, the debugger will break on the source line that launched the debugger. Now you can single-step through the installation code.