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.

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read