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.
ODOTServerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
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
0
Bill PrewCommented:
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
0
ODOTServerAuthor Commented:
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?
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Bill PrewCommented:
Here's an approach, see what you think.

set user_ffx_location=

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
)

if "%user_ffx_location%" NEQ "" (
  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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ODOTServerAuthor Commented:
That worked. Thanks!
0
Bill PrewCommented:
Welcome, glad that was useful.

~bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.