Deployment: ClickOnce and Other Methods
‘whereas a checked box will return “1”)
Dim startString As String = Me.Context.Parameters(cStartAfterInstall) If startString = “” Then Return
Dim shouldStart As Boolean = CBool(startString) If Not shouldStart Then Return
‘Service should be started, so create a process and wait for completion Dim proc As Process = Process.Start(CreateNetStartProcessInfo)
If Not proc.WaitForExit(cNETWaitTimeout) Then MsgBox(cNETWaitError)
End Sub
Private Function CreateNetStartProcessInfo() As ProcessStartInfo Dim x As New ProcessStartInfo(cNETProcessName, _
String.Format(cNETStart, cServiceDisplayName)) x.WindowStyle = ProcessWindowStyle.Hidden
Return x End Function
End Class
Also included in this listing is an event handler for the AfterInstall event that is used to start the service on completion of the installation process. By default, even when the startup is set to automatic, the service will not be started by the installer. However, when uninstalling the service, the installer does attempt to stop the service.
The user interface for this deployment project includes a Checkboxes (A) dialog using the User Interface view for the project. Refer to Figure 47-11 for a view of the default user interface. Right-click the Start node and select Add Dialog from the context menu. Highlight the dialog titled Checkboxes (A) from the Add Dialog window and click OK. This will insert the new dialog at the end of the installation process. The order of the dialogs can be adjusted using the Move Up/Down items from the right-click context menu on the nodes in the User Interface window.
Selecting Properties Window from the right-click context menu on the new dialog will bring up the Properties window. Set the property identifier for Checkbox1 to STARTAFTERINSTALL and the set the Visible property for the remaining checkboxes to false. As discussed earlier in the chapter, you also needed to add /STARTAFTERINSTALL=[STARTAFTERINSTALL] to the CustomActionData property for the assembly in the Custom Actions view of the deployment project. With this user input you can decide whether to start the service when the installer completes.
ClickOnce
Using a Windows installer is a sensible approach for any application development. However, deploying an installer to thousands of machines, and then potentially having to update them, is a daunting task. Although management products help reduce the burden associated with application deployment,
web applications often replace rich Windows applications because they can be dynamically updated, affecting all users of the system. ClickOnce is a new technology — included in version 2.0 of the .NET Framework — that enables you to build self-updating Windows applications. This section shows you how to use Visual Studio 2005 to build applications that can be deployed and updated using ClickOnce.