Using a batch file to test context-sensitive help
May 18th, 2005
Following on from my previous posting, I've found a smarter way to test context-sensitive help topics, using a Windows batch file. This way involves only one batch file, rather than two (as described previously).
Put the following batch file in your help directory. In my case this directory contains various subdirectories, one for each help project. The one I'm currently working on is called imuser, so this is the default project directory in the batch file, and the help file within this subdirectory is imuser.chm, so again this is the default. Change the two lines near the top of the batch file to change these defaults.
Once in place, all you do is double click the batch file in Windows Explorer, or double-click a shortcut to this batch file on your desktop, or in your Favorites, and a console window opens prompting you for the path, file name and map ID you want to use. You can hit Enter twice if you want to accept the defaults, but you must enter a map ID.
The help file is opened using keyHH.exe, which is a free download from Keyworks Software.
The batch file:
@echo off
REM =================================================================
REM test-help.bat
REM -------------
REM A Windows batch file for testing context-sensitive help.
REM Copyright Alistair Christie, 18 May 2005
REM =================================================================
REM Set the relative path to the directory containing the help file,
REM and the name of the help file.
REM Note the path is relative to the location of this batch file.
set helpdir=imuser
set helpfile=imuser.chm
REM Set %basedir% to the directory in which this batch file lives.
set basedir=%cd%
REM Print a blank line
echo+
echo CONTEXT-SENSITIVE HELP TESTER
echo =============================
echo Requires you to have downloaded and installed keyHH.exe
echo from http://www.keyworks.net/
echo+
echo The help file your are about to test is:
echo %helpdir%\%helpfile%
echo+
echo within the current directory:
echo %basedir%
:start
echo+
echo Path: %helpdir%
echo If this is not correct, enter the correct path
echo (without the trailing \), relative to the current directory.
REM Get user input and put it in the variable %newhelpdir%
set /p newhelpdir="If this *is* correct, just press Enter: "
if not {%newhelpdir%}=={} set helpdir=%newhelpdir%\
echo+
echo File: %helpfile%
echo Press Enter if this is correct.
REM Get user input and put it in the variable %newhelpfile%
set /p newhelpfile="Otherwise enter the correct file name: "
if not {%newhelpfile%}=={} set helpfile=%newhelpfile%
:enterMapID
echo+
REM If this is not the first time round, the user will already have supplied a map ID
if not {%mapid%}=={} echo Map ID: %mapid%.&set /p mapid="Press Enter or enter a new map ID: "
REM If this *is* the first time round, the user must supply a map ID
if {%mapid%}=={} set /p mapid="Enter a map ID: "
REM If they don't, print an error message and exit
if {%mapid%}=={} goto :noMapID
REM Change to the specified subdirectory
REM within the base directory (i.e. the directory
REM in which this batch file lives)
cd %basedir%\%helpdir%
REM Use keyHH.exe to open a help topic
REM using its map ID
echo on
keyHH.exe -myHelp -#mapid %mapid% "%helpfile%>$global_ContextWindow"
@echo off
echo+
echo Enter:
echo 'a' to choose another help file to test,
echo 'x' to exit
echo Or just press Enter to test another map ID.
echo+
REM Undefine %keypress%, just in case it's been used previously
set keypress=
REM Get user input
set /p keypress=""
REM If 'a' entered, clear the screen and go to the 'start' marker
if {%keypress%}=={a} cls.&goto :start
REM If 'x' entered, quit this program (closes the console window)
if {%keypress%}=={x} exit
REM If anything else entered (apart from a space),
REM clear the screen and go to the 'enterMapID' marker
cls.&goto :enterMapID
:noMapID
echo+
echo+
echo+
echo ERROR: You didn't enter a map ID
echo The program will now exit.
echo+
REM 'pause' prints a predefined message and waits for any keypress
pause
Pretty much all of this batch file is user interface window dressing. The guts of the file lie in the line:
keyHH.exe -myHelp -#mapid %mapid% "%helpfile%>$global_ContextWindow"
For this to work, you obviously need keyHH.exe, but you also need a help file that has a window definition called "$global_ContextWindow" and that has map IDs set up.
You could, however, remove ">$global_ContextWindow" from this line if you just want to use the default window for the help file.
When you run it, the batch file looks like this:

Potentially similar posts
- Scan for available IP addresses – August 2011
- My first (useful) Ruby program – June 2011
- Fix “No topics found” issue in CHM output – November 2010
- Perl basics for beginners (on Windows) – August 2010
- Preventing BBC iPlayer running all the time – November 2008