February 27, 2001
By Karen Kenworthy
IN THIS ISSUE
Now this is more like it! All last week, here at the secluded Power Tools workshop, the weather was awful. First the rain came. Then it got cold. Fog rolled in for a day, as the temperatures hovered near freezing just above the sodden earth. Then came storms, thunder, and lightning. One house down the road was damaged by the high winds.
But today the sun came out to stay. It's one of those days when everything glistens. Colors are clean and bright. The birds are singing, and the squirrels are frisky. You can feel the quickening everywhere you go. Everyone, and everything, is ready for Spring.
In last week's soggy Power Tools e-mail bag was a note from reader R. Curry. He followed our recent discussions of Compact Discs, and my new Autorun.inf Editor.
As you'll recall, Autorun.inf is a file found in the root directory of some CDs. This special file can contain the name of a program that will run automatically when the CD is inserted into a CD drive. The file can also specify an icon that will represent the CD in the My Computer folder, and the text that will appear below that icon.
Our conversation inspired R., I hope I'm not being to familiar, to try his own hand at burning a photo album CD for his family. First, he created a CD containing several scanned photos, and a program that displays miniature versions (called "thumbnails") of image files. Using the Autorun.inf Editor, he added an Autorun.inf file that caused the image viewer to be launched automatically when the CD is inserted.
The thumbnail program worked. But what he really wanted was a way to display his photos in HTML (HyperText Markup Language) pages, the kinds of pages that make up the Web. As he said in his note, "The thumbnail program would be unwieldy with the number of photos I have on the site. [A] Web photo album [could be] divided up into years, months, specialties, friends, etc. It is quite easy to link with HTML, but not with thumbnail programs."
Creating HTML pages to display photos is easy. Programs like Microsoft's FrontPage, and Allaire's HomeSite (I couldn't resist the plug) make it easy. With a little knowledge of the HTML language you can even craft pages using Windows' Notepad.
In addition to the photos, each page can contain one or more links to other pages in the album. One page, displayed first, can contain a table of contents, with links to all other pages.
You can put everything on a CD. But how do you cause table of contents page to be displayed automatically each time CD is inserted into a drive? For that matter, how can you cause a music file, spreadsheet, word processing document, or any other data file be automatically played or displayed?
Let's see ...
It's a Start
The Windows user interface has hidden the distinction between programs and data. Both are stored in disk files, and appear as icons on the Windows desktop and in My Computer folders. Double-click the icon of either type of file, and something happens -- a program is launched.
But under the covers, things are a bit more complicated. When you double-click a program's icon, Windows' job is easy. It just copies the program's instructions from disk to your computer's RAM. It then turns your computer's CPU over to those instructions, letting them tell the computer what to do next.
But when you double-click the icon of a data file, Windows heads straight for the Windows Registry. There, it finds the name and location of the program that, by default, handles files of the type being clicked. It then launches that program, as if its own icon had been clicked. Finally, it passes the program the name of the data file that actually was clicked.
Now you might think that the solution to R. Curry's problem is easy. Just place the name of his table of contents file in the Autorun.inf file, instead of the name of a program to be automatically started. But the bit of Windows that processes Autorun.inf files isn't as clever as the part that drives the user interface. Windows won't search the Registry for programs associated with files found in the Autorun.inf file.
OK, you're thinking, I have another trick up my sleeve. If a data file is associated with a program, why not place the name of that program in the Autorun.inf file? Enter the name of the data file in the program's command line. Most programs will automatically open any data file passed to it that way.
Unfortunately, the associations between programs and file types vary. One person may associate her Netscape Web browser with HTML files, while another associates those files with Microsoft's Internet Explorer. You may use WordPerfect to open most common word processing documents, while your colleague uses Microsoft Word. Music files, picture files, and spreadsheets can have different associations, depending on the programs a particular user prefers and installs. If your Autorun.inf file specifies a particular program, it may not work on all computers.
Wait! Microsoft has a program that will launch a program based on the type of a data file. It's called Start, and it works just like the Windows user interface. At a command prompt, type "Start" followed by the name of a data file, and the program associate with that file will be launched. The data file's name will be passed to the program, just as if you'd double-clicked the data file's icon.
So, all we have to do is have our Autorun.inf file launch Start. The command line specified in the Autorun.inf file will be the name of a data file. Start will select the appropriate program, based on the associations found in each user's Registry, and launch that program. The program will then open our data file.
Suppose, for example, R. Curry's table of contents HTML file is named "default.htm". He could place this command in his Autorun.inf file:
Then, when a family member inserts his CD, that person's favorite Web browser would be launched and asked to display his file.
Start also understands Web address, or URLs, such as https://www.karenware.com. Specify a URL in Start's command line, and it will launch your default Web browser and direct it there. This feature can be used to create CDs that automatically contact a Web site for updates, registration, etc.
A Fresh Start
This solution sounds perfect. And it almost is. The only gotcha is that not everyone has Start installed on their computer. You can't distribute Start with your CD. Microsoft doesn't permit it. And besides, each version of Start will only run on a single version of Windows. The Windows 98 version of Start won't run under Windows 95, for example.
But hey, this is Power Tools! We write our own programs around here. And a Start program that runs under all versions of Windows, and can be freely distributed on CDs, is an easy one to write.
And that's one of the things I did last week. I created PTStart, our own version of Windows Start. Like its predecessor, it can launch an associated program when told the name of a data file. It can also launch a browser, and navigate it to a URL if given a Web address instead. And of course, you can also ask PTStart to just run a program by specifying that program's name.
If you do ask PTStart to run a program, the program doesn't have to be on the same drive or CD as PTStart. If no path is specified PTStart will search for the program in the following locations:
- The directory where PTStart is stored.
- The Windows System directory (usually C:\Windows\System or C:\Windows\System32).
- The Windows directory (usually C:\Windows).
- The directories specified in your PATH environment variable.
This feature allows you to launch common Windows utilities, like Notepad.exe, without knowing exactly where they may be stored on a particular person's computer. As long as the file is present in any of the locations mentioned above it will be found by PTStart.
To take full advantage of PTSTart, I've updated the Autorun.inf Editor. Now it automatically adds PTStart to a CD and Autorun.inf file when needed, and updates command lines as necessary.
Both PTStart and the new Autorun.inf Editor v1.2 are available from my Web site at:
The Autorun.inf Editor's Visual Basic source code, and PTStart's C language source code, is available there too. As always, everything is free.
Tell Your Story
Before we part for another week, I'd like to ask for your help. Recently I've received several requests from readers, asking how they can learn to write computer programs. If you've found a good book, Web site, class, or other resource that you found helpful when starting to program, would you mind sharing it?
If so, drop me a note at email@example.com. Then we'll all get together and share the best suggestions. In the meantime, I'll be reading a few books, and writing some new programs. If you see me on the 'Net, or at the bookstore, be sure to wave and say "Hi!"
Power Tools Newsletter
- Directory Printer v5.4.4 Adds Unicode Characters Support
- Replicator v3.7.6 Eradicates Bug that caused Error 3
31712 Verified Subscribers
Subscribe to receive new issues of the newsletter about Karen and her free Power Tools.Click here to Subscribe