Hi there! Dax Pandhi here.
If you're Visual Basic programmer - which is kinda probable as you're on a VB Site - you know how painfully boring the Package & Deployment Wizard is. So what do you do when you want to customise your setup programs? Go out and buy a more interesting yet infinitely more expensive installation tool? NO! Stop wasting your money! You DON'T need a new setup creation tool! You have the P&D Wizard!
You might ask: "Is this geek crazy or what?" ... well, no, I'm not crazy. The Doctor confirmed it. Sort of. But it's the truth - you can customise the Package & Deployment Wizard setups to suit your needs.
So if you're interested in learning more about tweaking the setup tools you already have... read on!
I've been making customized setups for each of my clients since '98 with VB5. Boy, was it tough with VB5!! But VB6 adds more functionality and some more customizability, so it's hugely better for the developer.
In the VB Custom Setup Project we're going to create, I'll help you open doors to the secrets of P&D customization, allowing you to brighten the lives of your users and yourself.
And after all, if Microsoft made it, it MUST be good... Hey YOU!! Stop laughing!!
NOTE: This article is for VB6 users only. If you're an advanced VB5 programmer, you may want to read on to catch the general gist around 80% of the code is the same. But program with caution. And VB4 users? Sorry, you've got no chance... ;)
Before we get started, let's backup a few critical files we'll be playing with later:
- Open this folder: <VB Installation Directory>\Wizard\PDWizard\
- Copy this folder's sub-folder named "Setup1" to a different place. (COPY not CUT!)
- Change the project name to something different (see note)
- Make a back up to <VB Installation Directory>\Wizard\PDWizard\Setup1\
NOTE: This procedure is a precaution. The P&D Wiz might not work if the original copy is modified and doesn't meet its demands. Just don't try to be all heroic by skipping this!
WARNING: Windows 2000 users will not able to use the Package & Deployment wizard. The platform doesn't support it. This project can be completed on Windows 95 or 98 only. Win2k-created setups will cause an endless reboot!
Let's Get On With It
Righto, let's get started:
- Start Visual Basic
- Open the project "Setup1.vbp" (in <VB Installation Directory>\Wizard\PDWizard\)
First off, you need to know what each form and module does.
FrmBegin: Change-the-path-or-click-Install form.
FrmCopy: The dialog shown while files are copied
FrmDskSpace: Shows the hard disk space
FrmGroup: Program Files groups
FrmMessage: The generic message dialog (explained later)
FrmOverwrite: Asks if you want to overwrite a file or not.
FrmPath: You can specify where to install the software here.
FrmRemoteServerDetails: The Remote Server Details form.
FrmSetup1: The core of the setup program. Also the background of the windows we show.
FrmWelcome: The welcome form.
Top Tip: Do not modify any component unless you know what you're doing - otherwise, you'll end up knee-deep in crumbled code!!!
BasCommon: Lots of Global Constants, constants and common functions/subs.
BasLogging: This is for the error log for the Setup program removal utility.
BasSetup1: The other half of the setup program core. Too much to explain here. ;)
BasSetupRes: Tons of Global Constants.
ModRegistry: Module for handling the registry.
ModShell: Constants, Public Enum and some declarations for finding special folders like favorites, desktop, etc.
Resource File (setup1.res)
Contains the string table for this program (really useful for multilingual setups)
So, what are we going to do now?
First, we will add some new forms and customize the setup code. Then, we will create a more advanced and interesting background for the setup. Finally, we'll discuss what other features you can add with customisation... and those you can't.
So without wasting any more time, lets get busy!
Now, I'm going to show you how to add your own forms to a setup program a Welcome form, a License Agreement form, plus a possible 'Read Me' form.
First off, I'm going to add a Welcome form:
- Add a form and name it "frmWelcomeX"
There is already a form called FrmWelcome, - we'll rename it to FrmRegister later - but for now, we'll add this new form, FrmWelcomeX as a welcome form.
- Add two command buttons "cmdContinue" & "cmdCancel"
- Make their captions to "&Continue" and "E&xit" respectively. Make sure they're both at the bottom of the form
- Add a label with some welcome text like "Welcome to my setup" etc. - also, you may want to add a label with a copyright warning.
- Add the following code to the form:
Private Sub cmdContinue_Click()Unload MeFrmLicense.Show vbModal, Me' The Next FormEnd SubPrivate Sub cmdCancel_Click()ExitSetup Me, gintRET_EXITEnd SubPrivate Sub Form_Load()CenterForm MeEnd Sub
Adding a License Agreement
Next, we're going to add a form containing the License Agreement, a very important part of your software! Just a personal note - keep your License agreement as legally tight as possible, it's very important.
- Add a form to the project and name it "frmLicense". Make sure it is 5300 x 8800 (Height x Width)
- Add two command buttons "cmdContinue" & "cmdCancel". Make their captions "&Continue" and "E&xit Setup" respectively. Make sure they're both at the bottom of the form
- Add a text box named "txtLicense" and make sure the Locked and MultiLine properties are set to True
- Set the ScrollBars property to Vertical. Cut and paste your License agreement into the Text property
NOTE: You can't load a text file into the text box using the open xxx for input as
because the Setup1.exe is copied to the Windows directory and the license.txt file will be compressed in the Temp directory. So, the above method is best.
- Add the following code in frmLicense:
Private Sub cmdContinue_Click()Unload MeFrmReadme.Show vbModal, me ' Next formEnd SubPrivate Sub cmdCancel_Click()ExitSetup Me, gintRET_EXITEnd SubPrivate Sub Form_Load()CenterForm MeEnd Sub
In the same way, create frmReadme. It can be created JUST like frmLicense. The code is the same, just replace the cmdContinue_Click() code to:
Unload MeFrmRegister.Show vbModal
OK - all programs use different algorithms and registration stuff, so it is NOT up to me to tell how to do that. You are completely on your own - ;) - Best of luck!
But that is the great advantage of creating a custom setup program - you can add the registration process HERE instead of inside the software itself!
To sync with the project, don't create a new form, instead:
- Delete the controls on FrmWelcome and rename FrmWelcome to FrmRegister
- Delete the Form_Load() coding and it'll be ready! Don't delete any other coding
Why did we do that? The project is coded to load FrmBegin right after FrmWelcome. To change this, it would take a whole series of articles. But, in any case, the easy way is to make sure the last form you want to customize is frmWelcome!
There we go - the forms are finished! You've added a license agreement, a welcome form, a read-me-first, plus discussed registration.
When you next use the Package and Deployment Wizard, these new forms will all be available in your setup program! We'll cover how to make them appear straight away later.
Next, let's find out how to change the background of your setup application.
Now, we will change the visual appearance of the Setup background.
In Frmsetup1, comment all the code in DrawBackGround(). Now, turn to the Design view. Add whatever labels, images and stuff you like. Then, set the form's state to vbMaximized in the last line of Form_Load() (you will LOVE this when we finish the project!).
To make it more clear for you, here's a small example... look at the image below. You can also make one like it by just adding a few labels of BIG fonts and an image.
WARNING: The labels that already present on frmSetup1 (lblModify & lblDDE) should NOT be deleted. They are necessary and invisible at runtime, so they will not harm your design. If they interfere with your designing, move them away from the form by setting their Left & Top properties to 2000!
Like I said before, there's nothing like customization. ;)
NetCheck will ask the user if he wants to check if a newer version is available. If he says yes, the Internet Transfer Control will check for a newer version and report back.
In frmSetup1, add an Internet Transfer Control Inet1. Then, go to code view and add this code:
Public Sub NetCheck()On Error Go To ErrUpdate ' Err HandlingDim intMyVersion As IntegerDim b() As ByteDim intRemoteVer As IntegerDim strRemoteVer As StringDim iCheck As Integer' Be polite and ask the user!ICheck = MsgBox("Do you want to check if a never version _ is available on the web?" & _"If yes, then connect to the net and press YES.", _vbYesNo + vbQuestion, "New Version Available")If iCheck = vbNo Then Exit Sub' If user says no, exit sub' If yes, then open the file for reading!B() = Inet1.OpenURL("http://www.mysite.com/myfile.dat", 1)IntMyVersion = 45 ' Add your version hereStrRemoteVer = ""For t = 0 to Ubound(b)StrRemoteVer = strRemoteVer + Chr(b(t))Next' Check the infointRemoteVer = intMyVersionIf intRemoteVer > intMyVersion Then' Inform the user!MsgBox "A newer version of this software is available at www.mysite.com"ElseMsgBox "You have the latest version available."End IfErrUpdate:' Nothing hereEnd Sub
Explanation of NetCheck
The Inet control loads myfile.dat, a text file with just a version number. Then after loading it into memory, it checks whether the running software's version (intMyVersion) is smaller than the one on the Net (intRemoteVer). If it is, it prompts the user.
NOTE: You have to set the intRemoteVer to the current software version (by changing the myfile.dat value)
To make it easier, make sure both intMyVersion and intRemoteVer are only 1 or 2 digit integers. For example, 1 or 10 or 11, or something like that.
- After ShowWelcomeForm in frmSetup1's Form_Load(), add this code:
Well, now we get down to additional coding. By default, FrmWelcome is shown, but we want frmWelcomeX to show, so, in frmSetup1's code change the following:
Private Sub ShowWelcomeForm()If Not gfNoUserInput ThenFrmWelcome.Show vbModalEnd IfEnd Sub
Private Sub ShowWelcomeForm()If Not gfNoUserInput ThenFrmWelcomeX.Show vbModalEnd IfEnd Sub
With that, we finish our coding. Now:
- Compile Setup1.exe, overwriting the one in VB98\Wizards\PDWizard\
Now rename all copies of Setup1 everywhere on the hard drive the P&D Wizard sometimes replaces the new one with an older copy if found in c:\Windows\, so this is a precaution.
Now, every time you use the Package & Deployment wizard, it will use your new setup files!
Top Tip: After a setup is created by P&D Wizard, add the Internet Transfer Control and any other OCX used in setup1.exe to the bootstrap file. (Setup.lst). You may want to refer to MSDN VB Documentation for more reference. You can find it at http://msdn.microsoft.com/library/
In this long, long project, we accomplished a big task - creating our own customised setup program.
First, we added new forms like License Agreement, Read-me and registration, etc. Then, we implemented Web functionality into the setup. We also changed the background to something a little more pleasing!
Now, you're ready to knock your users socks off with a new shiny VB Setup program!
That's all for this article. If you need assistance with the setup project, have suggestions or comments, don't hesitate to mail me. You can reach me at www.extremetechnovision.com or firstname.lastname@example.org - Thanks! - Dax Pandhi
Dax Pandhi - is co-founder of Extreme Technovision. He lives in Bhuj, India and has over 10 years experience in programming. He holds the 1999-2000 international award for Best Amateur Animation, and has interests ranging from computers to dinosaur bone hunting. The Dax Pandhi personal Web page can be found at www.extremetechnovision.com/dax/