Announcement

Collapse
No announcement yet.

Button Properties - Force open document with Firefox

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Button Properties - Force open document with Firefox

    Hi,

    I am a total noob, so bear with me. I have an index.html file on my CD root directory. And all computers using the CD should have Firefox installed at the default folder C:/Program Files (x86)/Mozilla Firefox/firefox.exe

    I have a button on my menu page that I pick the Open Document option in the Button Properties Screen. I point it to the index.html file in the root directory. Is there an Add Action or Add Code I could paste into the Script Tab to force their computer to open the index.html with Firefox.exe instead of IE or their default browser? Furthermore, is it possible to have it search the Registry on the off chance they have installed Firefox to a different folder on their hard drive?

    Thanks in advance for any help.

  • #2
    Hi done a small app for you - firefox.apz
    Checks registry for firefox path and if exist then runs index.html with firefox
    If not then asks user if they want to install firefox - if yes installs else exits app
    Because I've included firefox installer in example too big (32Mb) to post so here is link

    https://*******/#!GeoyQKbK!Iwz-tSsXB...SNPERC6Ed91PuU

    I've tested with win7 & 10 vmware
    Cheers

    Comment


    • #3
      @sycore

      In regards your 1st question:
      You can force Firefox to open the index.html via the Shell.Execute() action:
      Code:
      Shell.Execute(_ProgramFilesFolder.."\\Mozilla Firefox\\firefox.exe", "open", _SourceDrive.."\\index.html", "", 1, false);
      But be mindful of the Global variable (_ProgramFilesFolder) being used in the above example - it actually translates as "Program Files (x86)". And therefore needs adjustment if intending to use on both x86 and x64 systems. Instead, to incorporate both system architectures, use:

      Code:
      if (System.Is64BitOS()) then
          fPath = _WindowsFolder:gsub("\\Windows", "").."\\Program Files\\Mozilla Firefox\\firefox.exe";
      else
          fPath = _ProgramFilesFolder.."\\Mozilla Firefox\\firefox.exe";
      end
      
      Shell.Execute(fPath, "open", _SourceDrive.."\\index.html", "", 1, false);
      Nb. Note location of the index.html in above example (ie. _SourceDrive) and adjust according to needs.

      .............................................


      In regards your 2nd question:
      Yes, it's technically possible to check the registry to return the location of the user's Firefox installation (but not practical). There's a directory string in the registry specifying where Firefox is installed. But is located in different places according to:
      • the version of Firefox installed
      • the user's OS
      • x86 or x64 system
      On Win7 x64:
      Code:
      local ffKey = "SOFTWARE\\Mozilla\\Firefox\\TaskBarIDs";
      local bRet = Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, ffKey);
      if (bRet) then
          local t = Registry.GetValueNames(HKEY_LOCAL_MACHINE, ffKey);
          Dialog.Message("Location", t[1]);
      end
      On WinXP x86 (running Firefox v52.5):
      Code:
      local ffKey = "SOFTWARE\\Mozilla\\Mozilla Firefox\\52.5.2 ESR (x86 en-US)\\Main";
      local bRet = Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, ffKey);
      if (bRet) then
          local s = Registry.GetValue(HKEY_LOCAL_MACHINE, ffKey, "PathToExe", true);
          Dialog.Message("Location", s);
      end
      ... So you can see it starts getting tricky (and messy). And that's just 2 configurations - there are many more which'd have to be taken into account. Much easier / more efficient to locate the user's Firefox installation via the File.Find() action instead. This also allows checking of both x86/x64 architectures:
      Code:
      [COLOR=#008000][I]-- Establish common global variable (_ProgramFilesFolder) for both x86 & x64 systems[/I][/COLOR]
      if (System.Is64BitOS()) then
          fPath = _WindowsFolder:gsub("\\Windows", "").."\\Program Files";
      else
          fPath = _ProgramFilesFolder;
      end
      
      [COLOR=#008000][I]-- Now search it for Firefox[/I][/COLOR]
      local t = File.Find(fPath, "firefox.exe", true, false);
      if (t) then
          Dialog.Message("Firefox found at:", t[1]);
      else
          Dialog.Message("Alert!", "Firefox not found");
      end

      Comment


      • #4
        Edit,

        Hmm, I stand corrected on the issue of using the registry for locating the Firefox installation. Seems that the HKLM Key:
        Code:
        Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\firefox.exe
        ... as shown in charliechaps' example is indeed consistent across the different OS types / architectures, after all.

        So, I stand corrected! And with new information, we must re-evaluate. So I recant my previous bad advice and say, 'Yes, for sure, go with this instead!'. Thanks very much for your fine, concise example, Charlie.

        However, I'd be remiss not to point out that your Shell.Execute() action (Line:01 - Button On Click) is actually failing. You have it a 'wee bit' ass-backwards & muddled there, my man. To force Firefox to act as the default browser for this action, we need to change it from:
        Code:
        Shell.Execute(_SourceFolder.."\\index.html", "open", "rkey", "", SW_SHOWNORMAL, false);
        to:
        Code:
        Shell.Execute(rkey.."\\firefox.exe", "open", _SourceFolder.."\\index.html", "", 1, false);
        You kinda had it in reverse. But also note the need to concatenate your rkey variable with "\\firefox.exe".
        Now it'll work as intended.

        Comment


        • #5
          Thank you both so much for your help. I think I can get it working now.

          Comment


          • #6
            Thanks Biohazard for the correction to Button code
            I didn't notice that when firefox installed it set itself to default browser
            So it opened the file and args were nothing as I had rkey in quotes

            Comment

            Working...
            X