Showing posts with label CD. Show all posts
Showing posts with label CD. Show all posts

Thursday, October 2, 2008

Running an Ancient dBASE IV Database from Removable Media


I needed to run a particular DOS application from CD, USB, or other removable drive.

This particular application is a database of local community service agencies built in dBASE IV, allowing the user to search among service providers or do keyword searches of available services.

It's nice because the contact and services information for hundreds of agencies could fit neatly on a 3.5" diskette, but not so nice because it's a DOS-based app. The app for my purposes needed to be able to run from CD or USB flash drive, the goal being to be able allow the user
to easily assess and play around with its features, and have a functional replica to use in refactoring its functionality into a more up-to-date database and user interface platform. That, and the fact that the computer to use for testing has no 3.5" diskette drive installed.

In the interests of time, I decided to create a batch file to execute the app. One twist, however, is that the app must run from the C: drive, because it's hard-coded to reference the primary hard drive in a PC.

I decided to create a batch file which would perform the following steps:
  1. Create a new folder on the temporary file area of the C: drive.
  2. Copy all files from the removable media to the new folder.
  3. Execute the DOS app.
  4. Upon exit, delete the folder from the C: drive.
The app would be running from within a DOS command prompt under Windows XP. One quirk, as CPU clock speeds have increased over the years, dBASE IV has issues which prevent it from executing normally on its own. Specifically, dBASE attempts to perform some temporary file housekeeping based on the system clock, and on any system faster than oh, 133 MHz or so (at least in my testing), dBASE would fail to launch.

Thankfully the utility IDXFIX proved to be the magic bullet for this little problem, my thanks to Gary White, creator of this, wherever he may be. This utility just needs to be run prior to dBASE to set up shop for it and presumably intercept and handle requests dBASE makes when trying to interface with the clock.

Here's the batch file, an explanation follows.
@ECHO OFF
CLS

md %temp%\myProg
xcopy *.* %temp%\
myProg /s /e /v /y
cd %temp%\
myProg\dbase
idxfix /I
dbase.exe %temp%\
myProg\db\myDB.prg
idxfix /U
cd %temp%\
del %temp%\
myProg\ /s /q
rd %temp%\
myProg\ /s /q

Now on to the explanation.

@ECHO OFF

CLS

  • Just tells the command prompt to not echo commands, and to clear the screen. In a way redundant, but this is habit from when I had to write batch files more frequently, and it does make testing a little cleaner.

md %temp%\myProg
  • This simply looks at the %temp% environment variable, which in Windows XP references the folder on the Windows install drive where temporary files are stored. By default this references a folder under C:\Documents and Settings\<userName>\Local Settings\Temp. I just changed this on the target system to a folder I created named C:\TEMP, for simplicity and to avoid any potential issues with long file names with this old DOS application.

xcopy *.* %temp%\myProg /s /e /v /y
  • This uses the command-line xcopy program to copy the entire file and folder structure from the removable media to the temporary file area on the C: drive. The parameters tell it to copy subdirectories, include empty subdirectories, verify the results, and automatically overwrite any existing files.

cd %temp%\myProg\dbase
  • Change directory to the dbase subfolder copied from the removable media. This is the folder where the dBASE executable, dbase.exe, lives.

idxfix /I
  • This loads the IDXFIX utility into memory as a TSR, short for Terminate and Stay Resident. The utility's execution doesn't stop any further actions in this particular instance of the command prompt, but still hangs out in memory to serve whatever purpose, in this case ensuring dBASE can execute properly.

dbase.exe %temp%\myProg\db\myDB.prg
  • This executes the dbase.exe executable and tells it to load the file myDB.prg, which represents the database application.

idxfix /U
  • When the batch file gets to this point, the user has quit dBASE. Thus, we unload the IDXFIX utility from memory.

cd %temp%\

  • Ensure we've changed to the temporary folder, so that our focus is NOT inside the folder or any subfolders of our copy of the database application. If this were the case, the next steps to remove the application files and folders from the target computer's hard drive would fail.

del %temp%\
myProg\ /s /q
  • Deletes files contained in the database application folder. The /s parameter ensures all files in all subfolders are deleted, while /q tells the delete operation to not ask for confirmation. We know what we're doing!

rd %temp%\
myProg\ /s /q
  • Removes the folder and all subfolders. Another option would've been to utilize the DELTREE executable, but DEL serves the purpose just fine as it's integrated into the XP command prompt, whereas DELTREE is a separate executable we'd need to store on the removable media.

In summary, this batch file has enabled us to run this ancient DOS-based database application comfortably from within a Windows XP command prompt. It sets up shop for itself on the C: drive, executes and enables the user to use the full functionality of the database, then wipes traces of itself from the hard drive upon exit.

This is a task which in a way seems rather pointless. However, these steps have enabled us to take an old DOS database application which previously could only run from a 3.5" diskette, and essentially make it portable so that it can now be run from any removable media.

If during some natural disaster or other crisis, someone needed this particular database to view on a laptop with no wifi handy, these steps would enable this accessibility.