Autorun Menu Creator in VB.NET

During a recent project, I have discovered the magic of  HTA scripting, and how powerful it is. I further discovered that HTA can be used to simplify my life, by creating CD/DVD Autorun menus.  This article will demonstrate how to use VB.NET to create an Autorun menu, through the use of HTML, HTA, CSS, JavaScript and VBScript.

Introduction

If you are not a scripting guru, don't worry too much as I will outline every aspect of HTA, JavaScript and VBScript, that pertains to our sample project, again, don't worry :)

AutoRun - for the uninformed :)

Have you noticed that when you purchase software, and you install it, that it automatically starts running after insertion?  If you have, then you have seen the AutoRun process.  How this happens is with a magical file called AutoRun.inf which is present on the CD / DVD.  This little file tells the system what to do with the disk's contents.  A normal Autorun.inf file looks like the following :

[AutoRun]
open=Program.exe
icon=Program_Icon.ico

This, tells the Operating system, to execute a program named Program.exe, and the CD's Icon will look like the Program_Icon.ico file

Magic.

HTML

HyperText Markup Language, is what every webpage is made of. HTML is the foundation of all web pages.  A Basic HTML document ( a Webpage ) looks like the following : )

<HTML>
<HEAD>
<TITLE>This Is A Basic Web Page</TITLE>
<BODY>This Is What You See When You View A Web Page</BODY>
</HTML>

If you were to copy and paste this code into Notepad, and save the document as WebPage1.htm - Note, you will have to Select the drop down arrow at the Save As Type drop down list, and select All Files - You will see that a webpage is magically created.  If you were to open it in your browser, you will see a webpage similar to the following.

There are many programs available to assist in making web pages, FrontPage, and Dreamweaver are the most popular.

HTA

HTA ( HTML Application ), is almost the same as HTML, but it has some subtle differences.  HTAs are not opened through your Internet browser, you don't need to, they are stand alone programs, only in HTML format.  OK, now, you will say that I'm contradicting myself, but let me explain it again.  HTAs are web page applications, understand better? Yes.  Now, the only difference between HTML and HTA is some additions to the HTML coding you may have.  Let us take the previous code listing, and transform it into an HTA application.

If necessary, open the above saved HTML file ( or copy and paste it again ) and make these small bolded modifications :

<HTML>
<HEAD>
<TITLE>This Is A Basic Web Page</TITLE>
<HTA:Application ID ="oHTA"
APPLICATIONNAME="Example1"
SYSMENU="yes"
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
CAPTION="yes"
ICON="Example.ico"
BORDER="Thin"
BORDERSTYLE="Raised"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
VERSION="1"
WINDOWSTATE="Maximize"/>

<BODY>This Is What You See When You View A Web Page</BODY>
</HTML>

Do not save this file as an .html file again, save this file with a .hta extension.

Once this file is saved properly, navigate to the location of where you have saved it to.  You will notice that the file doesn't have a webpage icon, but it has an icon similar to what an exe file has.  If indeed you had an icon named Example.ico, you would have seen a file with the Example icon.  Double click this file.

Whoa! Do you see it?  It runs just like a normal exe does!  And, it even has its own Maximize and Minimize buttons! 

I repeat, magic.

JavaScript

I live by a certain saying when Programming, that saying is : "There must Always be something complicated", usually when I say that, it is not as censored as the previous statement.  Why do I say so?  Well, JavaScript is a bird of a different colour.  It is sadly not as easy and straightforward as HTML - it mustn't be, it can't be, else the web wouldn't have become as powerful as it is today.  OK, now I'm scaring you...  Luckily, in our project, there isn't too much complicated JavaScript scripts. :) Phew! ME and JavaScript has never been friends.  OK, back to the point ( Why I hate JavaScript is an entire different book ).

JavaScript is a subset of Java, at least, that  is how I've always understood it.  JavaScript can only live on web pages, and cannot create Windows programs as its big brother Java can.  Most programming constructs are also present in JavaScript.:

JavaScript makes use of the following, the same way normal Programming Languages do :

Variables

Creating variables,. storing variables etc.  The only real difference is that you never have to supply a data type for the variable

Control flow structures

If statements, For loops, Do loops etc.  They still work in here

JavaScript's syntax is quite similar to C and C++, and Java as well.

JavaScript makes content on a web page dynamic.  Instead of having static - Wysiwyg ( What you see is what you get ) pages, you can use JavaScript to manipulate each object on the web page.

Without JavaScript, we would have been still in the good old Windows 95 days, when Internet was still new, and HTML the most brilliant thing on earth.  If you caught onto my sarcasm in the previous sentence, well, then you realise the power of JavaScript :)

VBScript

VBScript, yes, still scripting ( I'm rolling my eyes ).  Scripting is still something to get used to when you have been programming Windows Applications for more than 10 years -  well, to me.  I guess the whole thing about scripting is that it is different, don't get me wrong, scripting is very very powerful once you get the hang of it, actually too powerful - but that's another topic for another day.

VBScript, is Visual Basic's youngest brother - VBScript is just between VBA and VB.  Obviously, as the name implies, VBScript is also to be used for the internet, as far as I know, only Internet Explorer supports it?  VBScript is not as complex as JavaScript, but can get tricky as you will see.  Our project will rely heavily on VBScript to interrogate the disk drives of the machine.  Wow, you say you never thought VBScript could do that, I say yes, then it makes you wonder why so many viruses out there are just plain VBScript files.  Do you see now how powerful VBScript actually is?  Good.

CSS

Cascading Style Sheets allow you to separate formatting from content.  With a single CSS file, for example, you could format your entire website the same.  This reduces formatting HTML code, which in the end reduces chances for error, time, and file size.  CSS are made up of rules.  A normal CSS rule looks like the following :

H1 { font-family: Geneva, Arial, Helvetica, 
sans-serif;
font-size: 22px;
font-weight: normal;
color: Blue;
text-align: center; }

This will make all the H1 ( Heading 1 ) HTML tags either in Geneva, Arial, or Helvetica font faces, sized 22 pixels, blue, centered and not bold nor italic. For our program we will make use of Inline styles, which will be entered inside the HTML tags.

Autorun Menu Creator in VB.NET

Our Project

You may say that this guy doesn't stop talking today, and start banging on my door, and ask where is the project that can create Autorun menus? Here we go, buckle up!

The features of this program include the following :

  1. Provide a menu to run any programs from the CD / DVD
  2. Provide a Copyright notice, if you have sensitive info that may get stolen without permission
  3. Provide a means of accepting the terms and conditions of using this program
    1. Acceptance means allowance to use this program and will open up Windows Explorer
    2. Declining the notice will cause the CD / DVD to be ejected

What will happen is:

Our VB.NET program will contain all the necessary buttons for the above mentioned options.  Based on what was chosen and entered during runtime, the program will automatically generate the HTA file with all the necessary JavaScript, VBScript and HTML codings, based on the user's decisions.  After which, the program will generate the Autorun.inf file, and everything is then ready to be burnt on your CD / DVD. 

After you have burnt the files to disk, you can test it out.  When you insert the CD / DVD, this HTA file will start automatically and provide your user with the options you have decided upon when making the menu through your VB.NET program.  Sweet! Let's get started! - You may now say, Finally!

Design

Add  the following controls to your Project and set their properties as follows:

Control Property Value
Form Name frmAutoRun
  Width 804
  Height 417
  Text AutoRun Creator
GroupBox Name grpWindowStyle
  Text Window Style
GroupBox Name grpAppSettings
  Text Application Settings
GroupBox Name grpAppearance
  Text Window Appearance
GroupBox Name grpFeatures
  Text Features
GroupBox ( Inside grpFeatures ) Name grpActions
  Text Actions
GroupBox ( Inside grpFeatures ) Name grpButtons
  Text Buttons
GroupBox ( Inside grpFeatures ) Name grpAccept
  Text Accept Button
GroupBox ( Inside grpFeatures ) Name grpDecline
  Text Decline
CheckBox ( Inside grpWindowStyle ) Name chkSysMenu
  Text System Menu
CheckBox ( Inside grpWindowStyle ) Name chkMaximize
  Text Maximize Button
CheckBox ( Inside grpWindowStyle ) Name chkMinimize
  Text Minimize Button
CheckBox ( Inside grpWindowStyle ) Name chkTitle
  Text TitleBar
Label ( Inside grpWindowStyle ) Text Border
ComboBox ( Inside grpWindowStyle ) Name cboBorder
  Items Dialog
None
Thin
Label ( Inside grpWindowStyle ) Text Border Style
ComboBox ( Inside grpWindowStyle ) Name cboBorderStyle
  Items Normal
Complex
Raised
Static
Sunken
Button ( Inside grpWindowStyle ) Name cmdIcon
  Text Icon...
CheckBox ( Inside grpAppSettings ) Name chkShowInTaskBar
  Text Show In TaskBar
CheckBox ( Inside grpAppSettings ) Name chkSingleInstance
  Text Single Instance
Label ( Inside grpAppSettings ) Text Window State
ComboBox ( Inside grpAppSettings ) Name cboWindowState
  Items Normal
Minimize
Maximize
Label ( Inside grpAppSettings ) Text Version
Label ( Inside grpAppSettings ) Text Name
TextBox ( Inside grpAppSettings ) Name txtVersion
TextBox ( Inside grpAppSettings ) Name txtName
Label ( Inside grpAppearance ) Text ScrollBar Colours
Label ( Inside grpAppearance ) Text Background Colour
Label ( Inside grpAppearance ) Text Text Colour
ComboBox ( Inside grpAppearance ) Name cboScrollCol
  Items Red
Green
Blue
White
Black
ComboBox ( Inside grpAppearance ) Name cboBackCol
  Items Red
Green
Blue
White
Black
ComboBox ( Inside grpAppearance ) Name cboTextCol
  Items Red
Green
Blue
White
Black
Button Name cmdBackPic
  Text Background Picture
Radio Button ( Inside grpActions ) Name rdCopyRight
  Text CopyRight Info Only
Radio Button ( Inside grpActions ) Name rdMenu
  Text Launch Menu Only
Radio Button ( Inside grpActions ) Name rdLaunchCopy
  Text Launch Menu and CopyRight Info
Radio Button ( Inside grpButtons ) Name rdAcceptDecline
  Text Accept and Decline Buttons Only
Radio Button ( Inside grpButtons ) Name rdAllButtons
  Text Accept, Decline and Exit Buttons
Radio Button ( Inside grpButtons ) Name rdExitOnly
  Text rdExitOnly
Radio Button ( Inside grpAccept ) Name rdWinExplorer
  Text Launch Windows Explorer on Accept
Radio Button ( Inside grpAccept ) Name rdExitAccept
  Text Exit On Accept
Radio Button ( Inside grpDecline ) Name rdEject
  Text Eject CD on Decline
Radio Button ( Inside grpDecline ) Name rdExitDecline
  Text Exit on Decline
Button Name cmdSetWindowStyle
  Text Set
Button Name cmdAutoRun
  Text Create AutoRun File
Button Name cmdExit
  Text Exit
OpenFileDialog Name ofdIcon
OpenFileDialog Name ofdBackPic
Form Name frmSettings
  AcceptButton cmdOK
  Text Function Settings
Label Text Copyright Text
Label Text Launch Menu
Label Text Program 1
Label Text Program 2
Label Text Program 3
Label Text Accept Button Text
Label Text Decline Button Text
Label Text Exit Button Text
TextBox Name txtCopyRightInfo
  MultiLine True
  ScrollBars Both
TextBox Name txtApp1
TextBox Name txtApp2
TextBox Name txtApp3
Button Name cmdFont
  Text Font
Button Name cmdBrowse1
  Text Browse...
Button Name cmdBrowse2
  Text Browse...
Button Name cmdBrowse3
  Text Browse...
Button Name cmdAcceptText
  Text Change
Button Name cmdDeclineText
  Text Change
Button Name cmdExitText
  Text Change
Button Name cmdBack
  Text Back
Button Name cmdOK
  Text OK
FontDialog Name fdFont
OpenFileDialog Name ofdApp1
OpenFileDialog Name ofdApp2
OpenFileDialog Name ofdApp3

Autorun Menu Creator in VB.NET

Phew! You can wipe the sweat from your forehead now, we're done creating the design of our Autorun Menu Creator. Now, let us have a look at the code we have to enter to get this program working. - If you thought creating the design was hard work, I have bad news, unfortunately, for you.  The code is a lot of work, so you have to follow properly.  Three, Two, One, Lift Off!

Code

Imports

First things first.  Let us add the System.IO namespace to our frmAutoRun :

Imports System.IO 'File Processing Stuff

This is so that we can read from and write to files.

Private Level variables

Now, let us add all our Private variables :

Private WriteStr As String = "<HTML>" & Environment.NewLine 'Main String To Be Written To File
Private IconStr As String = "ICON=" 'Icon Information String
Private BackPicStr As String = "background : url(" 'Background Picture String
Private IconSel As Boolean = False 'Is Icon Selected ?
Private BackPicSel As Boolean = False 'Is BackgroundPicture Selected ?
Private Settings As New frmSettings 'Settings Form

All these variables will be used in more than one control's code, so as we go on, you will see where they all fit in.  The one variable to note is WriteStr.  This will be our main output into our HTA file.  All these variables initial values will seem a bit strange. Why is it so strange?  Because we have to dynamically write HTML, CSS, JavaScript, VBScript and HTA codes to our file.  All HTML files start with <HTML> to denote what follows is HTML code, so that is where WriteStr starts. IconStr starts with the Icon HTA code line, and all we need more with the Icon is its name.  IconSel will be used to determine if an icon was indeed selected. BackPicStr contains some CSS code for our Background Picture. We will write more background codes to it as we go on, but what it currently waits for is the URL ( source ) of the background picture.  BackPicSel will be used to establish whether or not a Background picture was chosen.  Settings represents the frmSettings Object.

cmdSetWindowStyle_Click

Most of the work will be done in here, so let us start here. 

cmdSetWindowStyle_Click Variables

First, we have to make variables for each of our program's settings :

Dim swFile As TextWriter 'TextWriter Object To Write Everything
Dim FileName As String 'FileName
The Textwriter object ( swFile ) will create our HTA file, FileName will represent whatever value the user has entered into the txtName textbox
'Window Style Options 
Dim SysMenuStr As String = "SYSMENU="
Dim MaxButStr As String = "MAXIMIZEBUTTON="
Dim MinButStr As String = "MINIMIZEBUTTON="
Dim CaptionTitleStr As String = "CAPTION="
Dim BorderStr As String = "BORDER="
Dim BorderStyleStr As String = "BORDERSTYLE="
'''''''''''''''''''''''

Our HTA program's Window Style options.  The above code will either have a System ( Control ) menu, Maximize button, Minimize button or not.  It will Show the Window's Title in the TitleBar or not.  The Border can be any of the following :

  • Dialog
  • None
  • Thin

The BorderStyle can be any of the following :

  • Normal
  • Complex
  • Raised
  • Static
  • Sunken

Each will give a different look to your HTA program's menu.  The best is to experiment with all the various options.

'Application Settings
Dim ShowInTaskBarStr = "SHOWINTASKBAR="
Dim SingleInstanceStr As String = "SINGLEINSTANCE="
Dim VersionStr As String = "VERSION="
Dim WindowStateStr As String = "WINDOWSTATE="
Dim AppNameStr As String = "<TITLE>"
'''''''''''''''''''''''

This section determines how your HTA application should behave.  ShowInTaskbar means that the HTA program window can either show a button in the Taskbar ( like any other normal program ), or not. SingleInstance means that the program can only be run once, or not.  Version represents the Program's version, like any other program. WinodwState can be any of the following :

  • Normal
  • Minimize
  • Maximize

AppNameStr, obviously, is your HTA program's name.

 'Window Appearance Options
Dim ScrollColStr As String = "<style>" & Environment.NewLine & "body {" & Environment.NewLine & "scrollbar-base-color: "
Dim BackColStr As String = "<BODY BGCOLOR="
Dim TextColStr As String = "TEXT="
''''''''''''''''''''''''

All the Window Appearance Options determine how your program will look, a colour scheme if you may. ScrollColStr is CSS code that will change the appearance of your window's scrollbar. BackColStr is the background colour of your HTA's body, written with HTML. TextCol ( also HTML code ) is the TextColour on your HTA program's body.  You will notice that I've included the same colours for all of these ( in Design time ), so the best is to use strong contrasting colours

 'Features 
Dim CopyStr As String = ""
Dim LaunchStr As String = ""
''''''''''''''''''''''''''

These 2 variables have nothing to do HTA, CSS or HTML.  These 2 variables will be used for our Copyright info which we will enter on frmSettings, and our Launch Menu, which we will also choose on frmSettings.  We will use JavaScript to write this information to our HTA document though.

Autorun Menu Creator in VB.NET

 'Buttons
Dim AcceptStr As String = "<input id=AcceptButton type=" & Chr(34) & "button" & Chr(34) & "value=" & Chr(34)
Dim DeclineStr As String = "<input id=DeclineButton type=" & Chr(34) & "button" & Chr(34) & "value=" & Chr(34)
Dim ExitStr As String = "<input id=ExitButton type=" & Chr(34) & "button" & Chr(34) & "value=" & Chr(34)
'''''''''''''''''''''''''

The above 3 lines will create our 3 buttons, depending on which Buttons options were chosen by the user.  AcceptStr will create the Accept button, DeclineStr creates the Decline Button, and the same with ExitStr.  This is HTML code, mostly.  If this was pure HTML code, it would have looked like this :

<Input ID=AcceptButton Type = "Button" Value = "Whatever You Want On The Button">
You will notice 2 things ( hopefully - if you are still awake ) In the HTML version I made use of quotation marks ( " " ) around the Type and Value. Some may argue that they are not really required, be that as it may, if you look at my code you will see I'm making extensive use of Chr(34). This is the ASCII representation of the quotation mark. You will also notice that I haven't yet included a Value on any of my buttons. This will be entered on frmSettings as well
 'Accept Button Stuff
Dim LaunchWinExAcceptStr As String = ""
Dim ExitAcceptStr As String
Dim OnClickAcceptExitStr As String = "onClick=" & Chr(34) & "AcceptLicence" & Chr(34) & ">"
Dim OnClickAcceptLaunchStr As String = "onClick=" & Chr(34) & "LaunchWinEx" & Chr(34) & ">"
''''''''''''''''''''''''''
These apply to the Accept button only. Depending on what features the user has chosen for this button, the necessary functions should exist on the HTA document. LaunchWinExAccept will write the JavaScript code to do launch the system's Windows Explorer. ExitAccept will make a JavaScript function to exit when Accept is clicked on. The next 2 lines are necessary to call the appropriate JavaScript function when the button has been clicked. you will notice the use of onClick for that exact purpose. You will also notice AcceptLicence and LaunchWinEx. These will be the JavaScript functions I will create to launch Windows Explorer or to exit the program.
 'Decline Button Stuff
Dim EjectCDDeclineStr As String
Dim ExitDeclineStr As String
Dim OnClickDeclineExitStr As String = "onClick=" & Chr(34) & "AcceptLicence" & Chr(34) & ">"
Dim OnClickDeclineEjectStr As String = "onClick=" & Chr(34) & "ExitCD" & Chr(34) & ">"
'''''''''''''''''''''''''
Same principle for the Decline button. EjectCDDeclineStr will create the VBScript function, named ExitCD, to eject the CD from the CD ROM. ExitDeclineStr will again create the JavaScript function named AcceptLicence to be used from the Decline button when it is clicked.
 'Exit Button Stuff
Dim OnClickExitStr As String = "onClick=" & Chr(34) & "AcceptLicence" & Chr(34) & ">"
Dim ExitButtonStr As String = ""
'''''''''''''''''''

Same is true for the Exit button.  AcceptLicence should be created through JavaScript first, then used when the Exit button is clicked. 

Yes, you will notice AcceptLicence 3 times, and yes, it may be written more than once to the HTA file, it wouldn't make a difference ( only in file size ), in a later update I will try to let each function write only once.

cmdSetWindowStyle_Click Inner workings

Add the following code after the variables' code :

        If chkSysMenu.Checked Then 'Is The System Menu Checked
            SysMenuStr += """yes""" & Environment.NewLine
        Else
            SysMenuStr += """no""" & Environment.NewLine
        End If

        If chkMaximize.Checked Then 'Is Maximized Checked
            MaxButStr += """yes""" & Environment.NewLine
        Else
            MaxButStr += """no""" & Environment.NewLine
        End If

        If chkMinimize.Checked Then 'Is Minimized Checked
            MinButStr += """yes""" & Environment.NewLine
        Else
            MinButStr += """no""" & Environment.NewLine
        End If

        If chkTitle.Checked Then 'Is TitleBar Checked
            CaptionTitleStr += """yes""" & Environment.NewLine
        Else
            CaptionTitleStr += """no""" & Environment.NewLine
        End If

        If cboBorder.SelectedIndex > -1 Then 'What Border Is Selected
            BorderStr += Chr(34) & cboBorder.SelectedItem.ToString & Chr(34) & Environment.NewLine
        Else
            BorderStr += Chr(34) & "Thin" & Chr(34) & Environment.NewLine
        End If

Quite straightforward.  Because we have given the SysMenuStr variable an initial value of SYSMENU=, we can now just appended either a "Yes" or a "No" depending on whether that particular checkbox was checked or not.  The same is true for MaxButStr, MinButStr, and CaptionTitleStrBorderStr we append whatever value was chosen from the cboBorder combobox.

Add the following code after the BorderStr code :

        If cboBorderStyle.SelectedIndex > -1 Then 'What BorderStyle Is Selected
            BorderStyleStr += Chr(34) & cboBorderStyle.SelectedItem.ToString & Chr(34) & Environment.NewLine
        Else
            BorderStyleStr += Chr(34) & "Normal" & Chr(34) & Environment.NewLine
        End If

        If chkShowInTaskBar.Checked Then 'Is Show In TaskBar Checked
            ShowInTaskBarStr += """yes""" & Environment.NewLine
        Else
            ShowInTaskBarStr += """no""" & Environment.NewLine
        End If

        If chkSingleInstance.Checked Then 'Is Single Instance Checked
            SingleInstanceStr += """yes""" & Environment.NewLine
        Else
            SingleInstanceStr += """no""" & Environment.NewLine
        End If

        If txtVersion.Text <> "" Then 'Version Of Our Program
            VersionStr += Chr(34) & txtVersion.Text & Chr(34) & Environment.NewLine
        Else
            VersionStr += """1.0""" & Environment.NewLine
        End If

        If cboWindowState.SelectedIndex > -1 Then 'What WindowState option Is Selected
            WindowStateStr += Chr(34) & cboWindowState.SelectedItem.ToString & Chr(34) & "/>" & Environment.NewLine
        Else
            WindowStateStr += Chr(34) & "Normal" & Chr(34) & "/>" & Environment.NewLine
        End If

Almost identical to the previous code segment, so I won't go into too much detail. The last 2 If Statements are the most interesting here.  VersionStr will make use of whatever value was entered into the txtVersion Textbox.  If nothing was entered, it will make the version 1.0.  WindowStateStr will make use of cboWindowState's selected item. The interesting here is this : "/>". "/>" closes the HTA's tag.  Refer back to the section entitled HTA.  After this tag, we will create the HTML Body tag.  Weird though is that I haven't actually written the HTA's start tag.  We will do that now.  This is why I have made each setting a different variable, so that it is easier to see where to add it into, as you will see when we get to writing all of this information to the file.

Autorun Menu Creator in VB.NET

Add this after the previous segment :

        If txtName.Text <> "" Then 'Our Program's Name
            FileName = txtName.Text
            AppNameStr += txtName.Text & _
            "</TITLE>" & Environment.NewLine & "<HTA:Application ID =" & """oHTA""" & Environment.NewLine & _
            "APPLICATIONNAME=" & Chr(34) & txtName.Text & Chr(34) & Environment.NewLine
        Else
            FileName = "HTA Application 1"
            AppNameStr += "HTA Application 1" & _
            "</TITLE>" & Environment.NewLine & "<HTA:Application ID =" & """oHTA""" & Environment.NewLine & _
            "APPLICATIONNAME=" & Chr(34) & "HTA Application 1" & Chr(34) & Environment.NewLine
        End If

        If cboScrollCol.SelectedIndex > -1 Then 'What ScrollBar Colour Is Selected
            ScrollColStr += cboScrollCol.SelectedItem.ToString & "; "
        Else
            ScrollColStr += "Red" & "; "
        End If

        If cboBackCol.SelectedIndex > -1 Then 'What Background Colour Is Selected
            BackColStr += Chr(34) & cboBackCol.SelectedItem.ToString & Chr(34) & " "
        Else
            BackColStr += Chr(34) & "Black" & Chr(34) & " "
        End If

        If cboTextCol.SelectedIndex > -1 Then 'What Text Colour Is Selected
            TextColStr += Chr(34) & cboTextCol.SelectedItem.ToString & Chr(34) & ">"
        Else
            TextColStr += Chr(34) & "White" & Chr(34) & ">"
        End If

        If Not IconSel Then 'If No Icon Selected
            IconStr += Chr(34) & "temp.ico" & Chr(34) & Environment.NewLine
        End If

Not bad as well. And you were scared! Ha!  The most interesting If statement to note here is the first one.  With this statement we determine whether or not an Application name has been entered or not.  What is interesting about the If statement is that it should reflect the Application's name in the <TITLE>.  <TITLE> is pure HTML, and it means the Title of the web page, or in this case, our HTA program.  Then, it also has to start writing the HTA definitions, which you will see with <HTA:Application ID =.  This, obviously will be one of the first variables we'll have to add to WriteStr.  The following 3 If statements determines the Scrollbar colour, Background colour and Text Colour.  You will also note that if no colour was selected, I have given each a different "default" colour. The last If statement here determines if we have selected an icon or not.  Later, in cmdIcon_Click we'll look at the icon's selection.

Now, it gets trickier.  Add the following 2 If statements just after the previous segment :

        If Not BackPicSel Then 'If No Background Picture Selected
            BackPicStr += Chr(34) & "temp.jpg" & Chr(34) & ");" & Environment.NewLine & _
            "background-repeat : no-repeat;" & Environment.NewLine & "background-attachment : fixed;" & _
            Environment.NewLine & "background-position : 50% 60%;" & Environment.NewLine & "}" & _
            "" & Environment.NewLine & "" & Environment.NewLine
        End If

        If rdCopyRight.Checked Then 'Is Copy Right Info Checked

            If Settings.ShowDialog Then
                CopyStr = Settings.SetFontStr & Settings.txtCopyRightInfo.Text & _
            "" & Environment.NewLine
            Else
                CopyStr = ""
            End If
        End If

The first If statement here is to be used when the user has not selected a Background picture, and use a default background picture named temp.jpg.  The CSS coding here however still remains the same whether or not a picture was selected. Background-repeat indicates that the picture shouldn't tile across the entire web page.  background-attachment means that the picture is fixed and cannot change.  The background-position indicates where the picture should be placed, i.e.. 50% on the x axis ( left to right ), 60% on the y axis ( top to bottom).  At the end of this IF statement, we also close the HTML <Head> section.  More on Background pictures in cmdBackPic_Click

The next If statement depends on frmSettings a lot.  frmSettings will be used to select the specific font we'd like our Copyright text to use, and what the Copyright text should actually be.

Now the fun starts.

        If rdMenu.Checked Then 'Is Launch Menu Checked
            LaunchStr = "<script language=" & Chr(34) & "VBScript" & Chr(34) & ">" & Environment.NewLine & _
             " Sub RunTool(AppPath)" & Environment.NewLine & _
             "Set objShell = CreateObject(" & Chr(34) & "Wscript.Shell" & Chr(34) & ")" & Environment.NewLine & _
             "objShell.Run AppPath" & Environment.NewLine & _
             " End Sub" & Environment.NewLine & _
             "</script> "

            If Settings.ShowDialog Then 'Show Settings Form
                Settings.LaunchArr(0) = Environment.NewLine & "<p><A onclick=" & Chr(34) & "RunTool('" & Settings.txtApp1.Text & "')" & Chr(34) & " style=" & Chr(34) & "cursor:hand;" & Chr(34) & ">Program 1</A><P>" & Environment.NewLine
                Settings.LaunchArr(1) = "<A onclick=" & Chr(34) & "RunTool('" & Settings.txtApp2.Text & "')" & Chr(34) & " style=" & Chr(34) & "cursor:hand;" & Chr(34) & ">Program 2</A><P>" & Environment.NewLine
                Settings.LaunchArr(2) = "<A onclick=" & Chr(34) & "RunTool('" & Settings.txtApp3.Text & "')" & Chr(34) & " style=" & Chr(34) & "cursor:hand;" & Chr(34) & ">Program 3</A><P>" & Environment.NewLine

            End If

        End If

When the Launch menu option is selected, we have to create the Sub or Function to enable us to launch programs from our web page. We are writing and building the function dynamically.  This is what it will end up looking like :

<script language="VBScript"> 
Sub RunTool(AppPath)
Set objShell = CreateObject("Wscript.Shell")
objShell.Run AppPath
End Sub
</script>

As you can see, it is VBScript and the sub's name is RunTool.  Inside we create a reference to the Windows Scripting Host, and via the WSH we run AppPath. AppPath is the parameter that will be passed to RunTool, and that is where the next lines comes in. After this VBScript sub procedure is in memory, we launch the Settings Form.  On the Settings Form we browse for each program ( the limit is 3 ), store it in the LaunchArr array, and create Links on the Web program  The links will end up looking like :

<A onclick="RunTool('Program1\Program.exe')" style="cursor:hand;">Program1</A><P>

When this link is clicked when the HTA application is running, it will launch that particular program. Funky, isn't it? I think so.

Next up we have :

        If rdLaunchCopy.Checked Then 'Is Launch Menu And Copy Right Selected
            If Settings.ShowDialog Then
                CopyStr = Settings.SetFontStr & Settings.txtCopyRightInfo.Text & _
            "</FONT>" & Environment.NewLine
            Else
                CopyStr = ""
            End If

            LaunchStr = Environment.NewLine & "<script language=" & Chr(34) & "VBScript" & Chr(34) & ">" & _
            Environment.NewLine & " Sub RunTool(AppPath)" & Environment.NewLine & _
            "Set objShell = CreateObject(" & Chr(34) & "Wscript.Shell" & Chr(34) & ")" & Environment.NewLine & _
            "objShell.Run AppPath" & Environment.NewLine & _
            " End Sub" & Environment.NewLine & _
            "</script> "

            If Settings.ShowDialog Then
                Settings.LaunchArr(0) = Environment.NewLine & "<p><A onclick=" & Chr(34) & "RunTool('" & Settings.txtApp1.Text & "')" & Chr(34) & " style=" & Chr(34) & "cursor:hand;" & Chr(34) & ">Program 1</A><P>" & Environment.NewLine
                Settings.LaunchArr(1) = "<A onclick=" & Chr(34) & "RunTool('" & Settings.txtApp2.Text & "')" & Chr(34) & " style=" & Chr(34) & "cursor:hand;" & Chr(34) & ">Program 2</A><P>" & Environment.NewLine
                Settings.LaunchArr(2) = "<A onclick=" & Chr(34) & "RunTool('" & Settings.txtApp3.Text & "')" & Chr(34) & " style=" & Chr(34) & "cursor:hand;" & Chr(34) & ">Program 3</A><P>" & Environment.NewLine

            End If

        End If

Basically the same as the just mentioned code segment, only difference is that we have to cater for both the launch menu as well as the Copyright info.  Nothing new here ( if you have read up to this point ), it is just a combination of 2 features.

Autorun Menu Creator in VB.NET

Our next If statement :

        If rdAcceptDecline.Checked Then 'Is Accept & Decline Buttons Selected
            OnClickExitStr = ""
            ExitStr = ""
            ExitButtonStr = ""

            If Settings.ShowDialog Then
                If Settings.AcceptTextClicked Then
                    AcceptStr += Settings.txtAcceptText.Text & Chr(34)
                Else
                    AcceptStr += "Accept" & Chr(34)
                End If
                If Settings.DeclineTextClicked Then
                    DeclineStr += Settings.txtDeclineText.Text & Chr(34)
                Else
                    DeclineStr += "Decline" & Chr(34)
                End If
            Else
                AcceptStr += "Accept" & Chr(34)
                DeclineStr += "Decline" & Chr(34)
            End If
        End If

Is also not too complicated.  This just finalises the Accept and Decline button strings so that they are complete. Refer to the 'Buttons variable declaration section.

Enter :

        If rdAllButtons.Checked Then 'Is All Buttons Selected
            ExitButtonStr = Environment.NewLine & "<SCRIPT LANGUAGE=" & Chr(34) & "VBScript" & Chr(34) & ">" _
            & Environment.NewLine & "Sub AcceptLicence" & Environment.NewLine & _
            "window.close()" & Environment.NewLine & "End Sub" & Environment.NewLine & _
            "</SCRIPT>"

            If Settings.ShowDialog Then 'Show Settings Form To Enter Button Labels
                If Settings.AcceptTextClicked Then
                    AcceptStr += Settings.txtAcceptText.Text & Chr(34)
                Else
                    AcceptStr += "Accept" & Chr(34)
                End If
                If Settings.DeclineTextClicked Then
                    DeclineStr += Settings.txtDeclineText.Text & Chr(34)
                Else
                    DeclineStr += "Decline" & Chr(34)
                End If
                If Settings.ExitTextClicked Then
                    ExitStr += Settings.txtExitText.Text & Chr(34)
                Else
                    ExitStr += "Exit" & Chr(34)
                End If
            Else
                AcceptStr += "Accept" & Chr(34)
                DeclineStr += "Decline" & Chr(34)
                ExitStr += "Exit" & Chr(34)
            End If
        End If

Here, we want all the buttons to be present.  We show the Settings form, and determine if any of the buttons labeled Change has been clicked.  If they were clicked, we know that the text for the buttons were entered and make use of that text on our buttons.  If the Change buttons were not clicked, we use default text for the buttons.

Enter the next segment :

        If rdExitOnly.Checked Then 'Is Exit Button Only Checked
            ExitButtonStr = Environment.NewLine & "<SCRIPT LANGUAGE=" & Chr(34) & "VBScript" & Chr(34) & ">" _
            & Environment.NewLine & "Sub AcceptLicence" & Environment.NewLine & _
            "window.close()" & Environment.NewLine & "End Sub" & Environment.NewLine & _
            "</SCRIPT>"

            If Settings.ShowDialog Then
                If Settings.ExitTextClicked Then
                    ExitStr += Settings.txtExitText.Text & Chr(34)
                Else
                    ExitStr += "Exit" & Chr(34)
                End If
            Else
                ExitStr += "Exit" & Chr(34)
            End If
        End If

We only want the Exit button here.  Note the sub it creates, in real life it will look like :

<SCRIPT LANGUAGE="VBScript">
Sub AcceptLicence

window.close()
End Sub
</SCRIPT>

This simply closes our HTA program's window.

Enter the next code :

        If rdWinExplorer.Checked Then 'Launch Windows Explorer
            AcceptStr += OnClickAcceptLaunchStr
            LaunchWinExAcceptStr = Environment.NewLine & "<SCRIPT LANGUAGE=" & Chr(34) & "VBScript" & Chr(34) & ">" _
            & Environment.NewLine & "Sub LaunchWinEx" & Environment.NewLine & _
             "Set objShell = CreateObject(" & Chr(34) & "Wscript.Shell" & Chr(34) & ")" & Environment.NewLine & _
            "objShell.Run(" & Chr(34) & "explorer.exe" & Chr(34) & ")" & Environment.NewLine & _
            "Set objShell = Nothing" & Environment.NewLine & _
            "End Sub" & _
            ""
        End If

What in the world happens here?

The rdWinExplorer button indicates that we want to open Windows Explorer when the Accept button was clicked.  It creates a VBScript function named LaunchWinEx to do so. LaunchWinEx actually will look like the following in our HTA program's code :

<SCRIPT LANGUAGE="VBScript">
Sub LaunchWinEx
Set objShell = CreateObject("Wscript.Shell")
objShell.Run("explorer.exe")
Set objShell = Nothing
End Sub</script>

Almost similar to the RunTool sub we've created earlier.  Only difference is that we hard code what it has to run, instead of making use of a parameter.

Enter :

        If rdExitAccept.Checked Then 'Exit
            AcceptStr += OnClickAcceptExitStr

            ExitAcceptStr = Environment.NewLine & "<SCRIPT LANGUAGE=" & Chr(34) & "VBScript" & Chr(34) & ">" _
            & Environment.NewLine & "Sub AcceptLicence" & Environment.NewLine & _
            "window.close()" & Environment.NewLine & "End Sub" & Environment.NewLine & _
            "</SCRIPT>"
        Else
            ExitAcceptStr = ""
        End If

No surprises here.  When Exit on Accept is clicked, it generates this function that simply closes the window.

Autorun Menu Creator in VB.NET

Enter this If condition :

        If rdEject.Checked Then 'Eject CD ROM
            DeclineStr += OnClickDeclineEjectStr

            EjectCDDeclineStr = Environment.NewLine & "<SCRIPT LANGUAGE=" & Chr(34) & "VBScript" & Chr(34) & ">" & _
            Environment.NewLine & "Sub ExitCD" & Environment.NewLine & _
            "Dim ts" & Environment.NewLine & _
            "Dim strDriveLetter" & Environment.NewLine & _
            "Dim intDriveLetter" & Environment.NewLine & _
            "Dim fs" & Environment.NewLine & _
            "Const CDROM = 4" & Environment.NewLine & _
            "On Error Resume Next" & Environment.NewLine & _
            "fs = CreateObject(" & Chr(34) & "Scripting.FileSystemObject" & Chr(34) & ")" & Environment.NewLine & _
            "strDriveLetter = " & Chr(34) & Chr(34) & Environment.NewLine & _
            "For intDriveLetter = Asc(" & Chr(34) & "A" & Chr(34) & ") To Asc(" & Chr(34) & "Z" & Chr(34) & ")" & Environment.NewLine & _
            "Err.Clear()" & Environment.NewLine & _
            "If fs.GetDrive(Chr(intDriveLetter)).DriveType = CDROM Then" & Environment.NewLine & _
            "If Err.Number = 0 Then" & Environment.NewLine & _
            "strDriveLetter = Chr(intDriveLetter)" & Environment.NewLine & _
            "Exit For" & Environment.NewLine & _
            "End If" & Environment.NewLine & _
            "End If" & Environment.NewLine & _
            "Next" & Environment.NewLine & _
            Environment.NewLine & _
            "Set oWMP = CreateObject(" & Chr(34) & "WMPlayer.OCX.7" & Chr(34) & ")" & Environment.NewLine & _
            "Set colCDROMs = oWMP.cdromCollection" & Environment.NewLine & _
            "For d = 0 To colCDROMs.Count - 1" & Environment.NewLine & _
            "colCDROMs.Item(d).Eject()" & Environment.NewLine & _
            "Next" & Environment.NewLine & _
            Environment.NewLine & _
            "Set owmp = Nothing" & Environment.NewLine & _
            "Set colCDROMs = Nothing" & Environment.NewLine & _
            "window.close()" & Environment.NewLine & _
            "End Sub" & Environment.NewLine & _
            "</SCRIPT>" & Environment.NewLine
        Else

            EjectCDDeclineStr = ""
        End If

I hear you saying : "I don't want to play anymore, we are no longer friends!" After this one.  I feel your sentiment, but look closer.  This is what the written function looks like inside your HTA program :

<SCRIPT LANGUAGE="VBScript">
Sub ExitCD
Dim ts
Dim strDriveLetter
Dim intDriveLetter
Dim fs
Const CDROM = 4

On Error Resume Next
fs = CreateObject("Scripting.FileSystemObject")
strDriveLetter = ""

For intDriveLetter = Asc("A") To Asc("Z")
	Err.Clear()
	If fs.GetDrive(Chr(intDriveLetter)).DriveType = CDROM Then
		If Err.Number = 0 Then
			strDriveLetter = Chr(intDriveLetter)
			Exit For
		End If
	End If
Next

Set oWMP = CreateObject("WMPlayer.OCX.7")
Set colCDROMs = oWMP.cdromCollection

For d = 0 To colCDROMs.Count - 1
	colCDROMs.Item(d).Eject()
Next

Set owmp = Nothing
Set colCDROMs = Nothing
window.close()
End Sub
</SCRIPT>

It does indeed look better.  What happens here is the following :

  1. We create the necessary variables to store our CD ROM / DVD ROM information
  2. We create a File System Object which determines whether or not the current pc has a CD ROM or DVD ROM
  3. The File System Object determines the Drive letter of the DVD / CD ROM
  4. A Windows Media Player 7 object is created - most pcs nowadays should have at least Windows Media Player 7 installed
  5. We make use of this WMP object to eject the CD / DVD ROM
  6. We set all the objects to nothing, in other words, we dispose of them
  7. We close the window

Finally, our last If statement for the cmdSetWindowStyle_Click event procedure :

        If rdExitDecline.Checked Then 'Decline
            DeclineStr += OnClickDeclineExitStr
            ExitDeclineStr = Environment.NewLine & "<SCRIPT LANGUAGE=" & Chr(34) & "VBScript" & Chr(34) & ">" _
            & Environment.NewLine & "Sub AcceptLicence" & Environment.NewLine & _
            "window.close()" & Environment.NewLine & "End Sub" & Environment.NewLine & _
            "</SCRIPT>"
        Else
            ExitDeclineStr = ""
        End If

If you followed this article up to this point, this was expected again. And yes, it is the AcceptLicence sub again, which just closes our window.

Autorun Menu Creator in VB.NET

Now, we have gathered all the required information, currently, whatever the user chose only still resides in memory.  We haven't written anything to our HTA file yet.  We will do so now. We must ensure though, that we write the variables in the correct order, else it will mess up our entire HTA file and the browser will be confused as to what to put where.

Add the next last lines into this sub :

        'Read All Info And Store Into One Variable
        WriteStr += AppNameStr & SysMenuStr & MaxButStr & MinButStr & CaptionTitleStr & _
        IconStr & BorderStr & BorderStyleStr & ShowInTaskBarStr & SingleInstanceStr & _
        VersionStr & WindowStateStr & LaunchStr & ExitAcceptStr & ExitButtonStr & _
        EjectCDDeclineStr & ExitDeclineStr & LaunchWinExAcceptStr & ScrollColStr & _
        BackPicStr & BackColStr & TextColStr & CopyStr & Settings.LaunchArr(0) & _
        Settings.LaunchArr(1) & Settings.LaunchArr(2) & AcceptStr & DeclineStr & _
        ExitStr & OnClickExitStr

        'Create Our HTA File
        swFile = System.IO.File.CreateText(Application.StartupPath & "\" & FileName & ".hta")

        'Write Everything
        swFile.Write(WriteStr)
        'Close The File
        swFile.Close()

We populate WriteStr with all the loaded variables, and add them in sequence, then, we simply write the contents of WriteStr into our HTA file.

cmdIcon_Click

Add this  code for the Icon button :

    Private Sub cmdIcon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdIcon.Click
        If ofdIcon.ShowDialog Then

            File.Copy(ofdIcon.FileName, Application.StartupPath & "\" & ofdIcon.FileName.Substring(ofdIcon.FileName.LastIndexOf("\") + 1))

            IconStr += Chr(34) & ofdIcon.FileName.Substring(ofdIcon.FileName.LastIndexOf("\") + 1) & Chr(34) & Environment.NewLine
            IconSel = True

        End If
    End Sub

If a valid icon has been selected, we copy that file to the root ( where our HTA file is ). It has to be in the root, as the Autorun file as well as our HTA file will expect it to be there.

cmdBackPic_Click

Add the following to the Background Picture button :

    Private Sub cmdBackPic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBackPic.Click
        If ofdBackPic.ShowDialog Then
            BackPicStr += Chr(34) & ofdBackPic.FileName & Chr(34) & ");" & Environment.NewLine & _
            "background-repeat : no-repeat;" & Environment.NewLine & "background-attachment : fixed;" & _
            Environment.NewLine & "background-position : 50% 60%;" & Environment.NewLine & "}" & _
            "" & Environment.NewLine & "" & Environment.NewLine
            BackPicSel = True
        End If
    End Sub

We have already covered the use of the CSS inline styles with the Background Picture.  Here, we just add the picture that was selected from the OpenFileDialog.

cmdAutoRun_Click

Our last button for this form, looks like :

    Private Sub cmdAutoRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAutoRun.Click
        Dim swFile As TextWriter
        Dim ARWriteString As String

        ARWriteString = "[autorun]" & Environment.NewLine & _
        "shellexecute = " & txtName.Text & Environment.NewLine & IconStr

        swFile = System.IO.File.CreateText(Application.StartupPath & "\Autorun.inf")

        swFile.Write(ARWriteString)
        swFile.Close()
    End Sub

Same principal actually as the cmdSetWindowStyle button ( when writing to a file ).  Here, we just dynamically create our Autorun.inf file, as mentioned earlier, without this file, the CD / DVD will not start automatically.  You will note the use of [autorun].  This indicates that this file should run upon insertion of the disk.  Then, I make use of the built in shellexecute function.  Some VB.NET'ers will know this function, and that it means that the default program for the specified file should be opened to run this file. Then we write the information to the file, and all is done! :)

Yes, I heard you shouting "Oh Yes!", when I said 'all is done'.  Remember, we still have to add the code for frmSettings. Take a break now, and then we cover it.

dot

dot

dot

Break over!

Autorun Menu Creator in VB.NET

frmSettings

Add the following Import to your Settings form :

Imports System.IO

Add the following variables to frmSettings :

    Public SetFont As Font
    Public SetFontStr As String = "<FONT FACE=" & Chr(34)
    Public LaunchArr(2) As String
    Public AcceptTextClicked As Boolean = False
    Public DeclineTextClicked As Boolean = False
    Public ExitTextClicked As Boolean = False

Yes, you see right, all of these variables are created in Public scope. Why? So that they can be manipulated by our first form. SetFont will be the selected Font. SetFontStr will contain the necessary HTML code to write to our HTA file.  LaunchArr is a string array that holds each of the selected programs for our Launch menu.  The following three variables just determine whether or not the Text for each button has changed or not.

cmdFont_Click

Add the following to your Font Button :

    Private Sub cmdFont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFont.Click
        If fdFont.ShowDialog Then
            SetFont = New Font(fdFont.Font, fdFont.Font.Style)
            SetFontStr += SetFont.Name & Chr(34) & " SIZE=" & Chr(34) & _
            SetFont.Size & Chr(34) & ">"
        End If
    End Sub

Here we simply select the Font to use for our Copyright text, and append SetFontStr where necessary.

The Browse Buttons.

Add the following 3 events ( each for the associated Browse button )

    Private Sub cmdBrowse1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBrowse1.Click
        If ofdApp1.ShowDialog Then
            txtApp1.Text = ofdApp1.FileName
            Directory.CreateDirectory(Application.StartupPath & "\Program1")
            File.Copy(txtApp1.Text, Application.StartupPath & "\Program1\" & ofdApp1.FileName.Substring(ofdApp1.FileName.LastIndexOf("\") + 1))
            txtApp1.Text = "Program1\" & ofdApp1.FileName.Substring(ofdApp1.FileName.LastIndexOf("\") + 1)
        End If
    End Sub

    Private Sub cmdBrowse2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBrowse2.Click
        If ofdApp2.ShowDialog Then
            txtApp2.Text = ofdApp2.FileName
            Directory.CreateDirectory(Application.StartupPath & "\Program2")
            File.Copy(txtApp2.Text, Application.StartupPath & "\Program2\" & ofdApp2.FileName.Substring(ofdApp2.FileName.LastIndexOf("\") + 1))
            txtApp2.Text = "Program2\" & ofdApp2.FileName.Substring(ofdApp2.FileName.LastIndexOf("\") + 1)

        End If
    End Sub

    Private Sub cmdBrowse3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBrowse3.Click
        If ofdApp3.ShowDialog Then
            txtApp3.Text = ofdApp3.FileName
            Directory.CreateDirectory(Application.StartupPath & "\Program3")
            File.Copy(txtApp3.Text, Application.StartupPath & "\Program3\" & ofdApp3.FileName.Substring(ofdApp3.FileName.LastIndexOf("\") + 1))
            txtApp3.Text = "Program3\" & ofdApp3.FileName.Substring(ofdApp3.FileName.LastIndexOf("\") + 1)

        End If
    End Sub

All of them work the same.  The OpenFileDialog gets shown, once a valid selection was made, we create a directory for each separate program. Program1, Program2, and Program3.  We copy the application into that directory, and we display the source to this program - which will later be used in our HTA file.

The Boolean variables

    Private Sub cmdAcceptText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAcceptText.Click
        AcceptTextClicked = True
    End Sub

    Private Sub cmdDeclineText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDeclineText.Click
        DeclineTextClicked = True
    End Sub

    Private Sub cmdExitText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExitText.Click
        ExitTextClicked = True
    End Sub

These variables get populated with each click of the appropriate Change button.  This is so that we know, the user has changed the text of the specific button, so that we can include this on our HTA program.

The next sub, simply hides the settings form ( as if you didn't even know that yet ) :

    Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
        Me.Hide()
    End Sub

Guess what?  That is all there is to it!  If you have done everything correctly, feel free to test out your program now.  Everything will be output to the Bin\Debug folder ( where your program's exe usually resides ).  Play around with all the various options.  Now you may ask, how do I run the HTA file? Simple! Just double click on it! Magic

You can now write these files to a CD or DVD, and further test it out.  You can use a CD / DVD burner of your choice, or use my Simple Burn, which you will find here :

http://www.codeguru.com/csharp/.net/net_general/tipstricks/article.php/c15201/

Conclusion

Wow, I can not believe how big this article got! I hope this was as useful and as much fun as it was for me, to you.  I have attached the source here, just for in case you didn't follow 100%

Until next time, cheers!



About the Author

Hannes du Preez

Hannes du Preez is a Microsoft MVP for Visual Basic. He is a trainer at a South African-based company. He is the co-founder of hmsmp.co.za, a community for South African developers.

Downloads

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • Learn How A Global Entertainment Company Saw a 448% ROI Every business today uses software to manage systems, deliver products, and empower employees to do their jobs. But software inevitably breaks, and when it does, businesses lose money -- in the form of dissatisfied customers, missed SLAs or lost productivity. PagerDuty, an operations performance platform, solves this problem by helping operations engineers and developers more effectively manage and resolve incidents across a company's global operations. …

Most Popular Programming Stories

More for Developers

RSS Feeds