Automatically Updating Visual Basic 6 Applications: Part I

 

Scott Swigart
Swigart Consulting LLC

May 2006

Applies to:
   Microsoft Visual Basic 6.0
   Microsoft Visual Basic 2005
   Microsoft Visual Basic Express 2005 Edition
   Microsoft Visual Studio 2005
   .NET Framework 2.0

Summary: This article shows how you can add automatic updating functionality to your existing Visual Basic 6.0 applications, using features now available with the .NET Framework 2.0. (10 printed pages)

Click here to download the code sample for this article.

Contents

Introduction
ClickOnce Deployment
ClickOnce Deploying a Visual Basic 6.0 Application
Versioning
Conclusion

Introduction

Deploying applications is hard. It takes time to build and test installers. Applications often require additional COM components to operate, and these components require registration. You also have to consider how you're going to physically distribute the bits. Will you burn a CD? Will you zip them up and place them on a website for downloading? Will you use a product like SMS to push them out?

Versioning applications is also hard. You may have previous versions of the application installed that may require removal. Applications today are expected to somehow know when a new version is available, prompt you to see whether you want to install it, and then take care of the rest.

Visual Basic 6.0 allows you to build installers to address some of these issues. Third-party products offer even more capabilities for deploying and versioning application, but automatic updating can be tricky. Visual Basic 6.0 provides no capabilities for making an application that automatically detects, downloads, and installs a new version of itself. Rolling your own capability for this would be, for lack of a better term, hard.

ClickOnce Deployment

Automatic application updating is a feature that Microsoft has been working to simplify. With Visual Studio 2005 and the .NET Framework 2.0, Microsoft provides a built-in solution for robust application deployment and automatic updating. While this technology, known as ClickOnce deployment, was developed with .NET applications in mind, it can be used to automate the deployment and updating of Visual Basic 6.0 applications. Considering that bazillions of lines of Visual Basic 6.0 code will continue to run in production for some time, this might be a useful thing.

Getting Started

To begin with ClickOnce deployment, it's important to have the latest version of Visual Studio. If you already have Visual Studio 2005 installed, that's great! Otherwise, I strongly recommend that you download and install the free Visual Basic Express. Visual Basic Express provides all the functionality that you need in order to ClickOnce deploy applications. It's a free, trimmed-down version of the full Visual Studio 2005, but unlike typical evaluation software, it doesn't timeout.

This article will walk you, step by step, through the process of ClickOnce deploying a Visual Basic 6 application. The steps in this article are written for Windows XP with Internet Information Server (IIS) installed. This technique should work on other versions of Windows, but the steps for configuring Internet Information Server will vary slightly.

The first steps will walk you through using Visual Basic Express to ClickOnce deploy a Visual Basic .NET application. This .NET application will become the launcher for your Visual Basic 6.0 application. It will check for, download, and install new versions automatically.

  1. Start Visual Basic Express or Visual Studio 2005.

  2. Click the File menu, and then click New Project.

  3. Create a Visual Basic Windows Application. Name the application MyAppLauncher.

  4. Click the File menu, and then click Save All.

  5. In the Save Project dialog box that appears, click Save.

    You should now see the form designer, which will let you create the launcher application. Initially, this will be a trivial application that will let you get familiar with ClickOnce deployment. Later, this will include your Visual Basic 6.0 application, and you will see how it can automatically update itself.

  6. In the Solution Explorer, double-click My Project.

  7. Click the Publish tab on the left side.

    The Publish tab shows the options related to ClickOnce deployment (see Figure 1). When you ClickOnce deploy your application, it will be posted on a website, allowing the user to download, install, and execute the application with a single click. The application will also download and install any needed prerequisites, such as the .NET Framework 2.0.

    Aa697430.autoupdatvb6apps01(en-US,VS.80).gif

    Figure 1. ClickOnce settings

  8. On the Publish tab, click Prerequisites if you want to select additional packages to download and install with your application (see Figure 2). The .NET Framework 2.0 is a requirement, but you might also want to download and install MDAC 2.8, for example.

    Aa697430.autoupdatvb6apps02(en-US,VS.80).gif

    Figure 2. Selecting prerequisites

  9. On the Publish tab, click Updates to configure when the application checks for new versions (see Figure 3). The default is to check before the application starts, but you can have the application check in the background while it's running.

    Aa697430.autoupdatvb6apps03(en-US,VS.80).gif

    Figure 3. Configuring when to check for updates

  10. On the Publish tab, click Publish Now to compile and deploy the application to your local Web server. Once the application has been deployed, the Web page in Figure 4 will be displayed, allowing you, or any other user, to download and install the prerequisites and the application.

    Aa697430.autoupdatvb6apps04(en-US,VS.80).gif

    Figure 4. Web installation page

Little Details

Unfortunately, at this point, it's necessary to pull back the covers on ClickOnce deployment just a bit, and talk about what's going on behind the scenes. When you publish your application to a website, it will create on the Web server a folder like the one shown in Figure 5.

Aa697430.autoupdatvb6apps05(en-US,VS.80).gif

Figure 5. Files published to the Web folder

You'll notice some files with an .application extension. If you drill into the MyApplicationLauncher_1_0_0_0 folder, youll also find files with .deploy and .manifest extensions. By default, Internet Information Server doesn't correctly serve these up, and as a result, if someone tries to install the application through the Web, it won't work. There's a one-time change that you need to make to Internet Information Server's settings so that it correctly supports ClickOnce deployment.

Configuring Internet Information Server

On Windows XP, the following steps will correctly configure IIS. If you're running on a different operating system, the steps will vary slightly.

  1. Click the Start menu, and then click Control Panel. Then, open Administrative Tools > Internet Information Services.

  2. Expand the local computer name, expand Web Sites, right-click Default Web Site, and click Properties (see Figure 6).

    Aa697430.autoupdatvb6apps06(en-US,VS.80).gif

    Figure 6. Selecting Default Web Site Properties

  3. In the Properties dialog box, click the HTTP Headers tab, and then click File Types.

  4. In the File Types dialog box, add the file types shown in Figure 7.

    Aa697430.autoupdatvb6apps07(en-US,VS.80).gif

    Figure 7. Configuring file extensions for ClickOnce deployment

  5. Return to the Web installation page shown in Figure 4, and click Install.

    The application installer will download and run, and the Application InstallSecurity Warning dialog box will appear (see Figure 8).

    Aa697430.autoupdatvb6apps08(en-US,VS.80).gif

    Figure 8. Prompt for application install

  6. Click Install.

    The application will install and run.

ClickOnce Deploying a Visual Basic 6.0 Application

With a basic knowledge of ClickOnce in hand, you can easily include other files in your deployment. In the following steps, you will include a Visual Basic 6.0 application as part of your ClickOnce deployment, and you will configure the launcher application to start the Visual Basic 6.0 application after it ensures that the latest version is installed.

  1. Start Visual Basic 6.0.

  2. In the New Project dialog box, select Standard Exe, and click Open.

  3. Change the caption property of Form1 to VB6 App.

  4. From the toolbox, add a Command button to Form1.

  5. In the Click event of the Command button, enter the following code:

    Private Sub Command1_Click()
    MsgBox "Hello World from VB6"
    End Sub
    

  6. Click the File menu, and then click Save Project As.

  7. Save the project in the same folder as the MyAppLauncher.vbproj file.

  8. Click the File menu, and then click Make Project1.exe.

  9. In the Make Project dialog box, click OK.

    You now have a simple Visual Basic application that can be ClickOnce deployed along with your Visual Basic .NET launcher.

  10. Switch to Visual Basic Express.

  11. Click the Project menu, and then click Add existing item.

  12. In the Add Existing Item dialog box, in the File Types drop-down list, click All Files (*.*).

  13. Select Project1.exe, and click Add.

    If you don't see Project1.exe, ensure that you saved your Visual Basic 6 project to the correct folder in Step 7.

  14. In the Solution Explorer, select Project1.exe.

  15. Press F4 to view the Properties window.

  16. In the Properties window, set the Copy to Output property to Copy if newer.

    By adding the Visual Basic 6 executable to your Visual Basic .NET solution, and indicating that you want it copied to the output, you are ensuring that the Visual Basic 6 application will be included in your ClickOnce deployment. The only remaining task is to modify the launcher application so that it will launch the Visual Basic 6 application.

  17. In the Solution Explorer, double-click Form1.vb.

  18. Double-click Form1 in the designer to switch to code view.

    You should be in the Form1_Load event handler.

  19. Enter the following lines of code in Form1_Load:

    Process.Start("Project1.exe")
    Me.Close()
    

    You can now publish the new version of the application. This time, the Visual Basic 6 application will be included with your launcher.

  20. In the Solution Explorer, double-click My Project.

  21. Click the Publish tab.

  22. Click Publish Now.

  23. When the MyAppLauncher Web page appears, click Install.

    The Visual Basic 6 application, deployed through ClickOnce, should appear as shown in Figure 9.

    Aa697430.autoupdatvb6apps09(en-US,VS.80).gif

    Figure 9. Visual Basic 6 application deployed through ClickOnce

Versioning

Now that you've completed the initial deployment of your Visual Basic 6 application, deploying a new version becomes simple. Essentially, you make changes to your Visual Basic 6 application, republish it, and that's it. The following steps will walk you through the details:

  1. Switch to Visual Basic 6.0.

  2. In the Project Explorer, double-click Form1.vb.

  3. Set the BackColor for Form1 to something obviously different, like red.

  4. Click the File menu, and then click Make project1.exe.

  5. In the Make Project dialog box, click OK.

  6. When prompted to replace Project1.exe, click Yes.

  7. Switch to Visual Basic Express.

  8. In the Solution Explorer, double-click My Project.

  9. Click the Publish tab.

  10. Click Publish Now.

    A new version has now been posted to the server. The next time the user runs the application, the new version will automatically download, install, and run.

  11. Don't install MyAppLauncher through the Web page. Instead, just launch the existing version through the Start menu. (Click the Start menu, point to All Programs, and then click MyAppLauncher.)

    Note that the dialog box shown in Figure 10 briefly appears.

    Aa697430.autoupdatvb6apps10(en-US,VS.80).gif

    Figure 10. Application automatically checking for a new version

  12. A new version is detected automatically, and you're prompted to install.

    Aa697430.autoupdatvb6apps11(en-US,VS.80).gif

    Figure 11. Prompt to install the new version

  13. When you click OK, the new version installs and runs.

    Aa697430.autoupdatvb6apps12(en-US,VS.80).gif

    Figure 12. New version of the Visual Basic 6 application

Conclusion

Hopefully, the technique shown in this article has opened a new door for how you deploy some of your applications. In this first article, you have learned how to deploy a Visual Basic 6 application through ClickOnce deployment. Stay tuned for Part II, where you will learn how to deploy COM object and ActiveX controls along with your Visual Basic 6 application.

 

About the author

Scott Swigart spends his time consulting, authoring, and speaking about converging and emerging technologies. With development experience going back over 15 years, and by staying in constant contact with future software development technologies, Scott is able to help organizations get the most out of today's technology while preparing to leverage the technology of tomorrow. Scott is also the author of several .NET books, a certified Microsoft trainer (MCT) and developer (MCSD), and a Microsoft MVP. Feel free to contact the Scott at scott@swigartconsulting.com, or check out his latest musings at blog.swigartconsulting.com.

© Microsoft Corporation. All rights reserved.