Link to home
Start Free TrialLog in
Avatar of ODOTServer
ODOTServerFlag for United States of America

asked on

Script to find install path of firefox

Creating this to copy the Mozilla.cfg and local-settings.js files to any machine that has firefox installed.


Basically needing a script to find the path firefox is installed, change the path to a variable and then copy two files to the Mozilla install directory.  writing it as a batch file but if you have a powershell script that will work that would be fine too. This needs to be able to un on windows 7 machines. It will be applied to the computer group policy script setting.

This is what I have so far. I'm having a problem deleting the \firefox.exe from the end of the path.  Its only pulling the path directly to the firefox.exe.

FOR /F "tokens=1,2* delims= " %%i in ('reg query "HKLM\Software\Clients\StartMenuInternet\FIREFOX.EXE\shell\open\command" /s ^| find "Default"') do SET user_ffx_location=%%k

set %user_ffx_location%=%changeffx%

set _changeffx
set _result=%_\firefox.exe=%
%changeffx%=%userffx_location%



      copy \\fileshare\share\mozilla.cfg "%user_ffx_location%\mozilla.cfg"
      copy \\fileshare\share\local-settings.js "%user_ffx_location%\pref\local-settings.js"
     )
  )


Thanks.
Avatar of Bill Prew
Bill Prew

Does this help, you can can get just the folder of the EXE with the ~dp modifiers to the loop variable.  It will have a trailing "\".

@echo off
setlocal

for /f "tokens=1,2* delims= " %%i in ('reg query "HKLM\Software\Clients\StartMenuInternet\FIREFOX.EXE\shell\open\command" /s ^| find "Default"') do (
  set user_ffx_location=%%~dpk
)

echo %user_ffx_location%

Open in new window

~bp
So your code would be:

for /f "tokens=1,2* delims= " %%i in ('reg query "HKLM\Software\Clients\StartMenuInternet\FIREFOX.EXE\shell\open\command" /s ^| find "Default"') do (
  set user_ffx_location=%%~dpk
)

copy \\fileshare\share\mozilla.cfg "%user_ffx_location%mozilla.cfg"
copy \\fileshare\share\local-settings.js "%user_ffx_location%pref\local-settings.js"

Open in new window

~bp
Avatar of ODOTServer

ASKER

Great, thanks. Is there a way to end the script if it can't find the registry key? So it doesn't just error if firefox isn't installed?
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That worked. Thanks!
Welcome, glad that was useful.

~bp