by Jon Ripley, May 2006, rewritten February 2008

To find the installation directory of BBC BASIC for Windows use the following FN_ReadBB4WInstallPath function which takes no parameters and returns a path to where BBC BASIC is installed or an empty string if no installation is found:

      DEF FN_ReadBB4WInstallPath
      LOCAL hkey%,res%,lbuf%,type%,key$(),P%
      lbuf%=255:DIM buf% LOCAL lbuf%,key$(5)
      key$()="Software\R T Russell\BBC BASIC for Windows", "InstallPath", \
      \      "Software\Microsoft\Windows\Html Help", "bbcwin.chm", \
      \      "Software\Microsoft\Windows\Help", "bbcwin.hlp"
      WHILE $$buf%="" AND P%<6
        SYS "RegOpenKeyEx", &80000002, key$(P%), 0, &20001, ^hkey% TO res%
        IF res%=0 THEN
          SYS "RegQueryValueEx", hkey%, key$(P%+1), 0, ^type%, buf%, ^lbuf% TO res%
          SYS "RegCloseKey", hkey%
        IF $$buf%>"" IF RIGHT$($$buf%)<>"\" $$buf%+="\"

Here we check in order of preference three three known registry locations where the BB4W installation path may be stored. The first is an installation path set by recent versions of the install and upgrade tools when they are used. The second is a path to the documentation and the third is a legacy key required to cope with early versions of BBC BASIC for Windows.

The following code demonstrates the use of FN_ReadBB4WInstallPath:

      PRINT "BBC BASIC was installed in: ";FN_ReadBB4WInstallPath