Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

What I am looking to do is create a batch file to replace teh cert8.db file in a users application data folder as well as insert a line of text into one of the prefs.js file. Normally this would be easy, the issue is that there is a good chance some of my users have multiple firefox profiles so I would like to have a script to to replace all cert8.db files in the firefox/profiles folder and insert 1 line of next into all prefs.js files in the firefox/profiles folder.

Can this be done? I am willing to use vb if possible.

share|improve this question
    
Task 1 is to locate the firefox profile storage location. then locating the cert8.db files and replacing is easy, if they are not locked. The prefs.js - do you merely want the text added to the end of the files, no matter what else is in them? –  foxidrive Jul 26 '13 at 1:06

2 Answers 2

FOR /D %%i IN (C:\Users\*.*) Do FOR /D %%j IN (%%i\AppData\Roaming\Mozilla\Firefox\Profiles\*.*) Do (
    CALL :ReplaceDB "%%j\cert8.db"
    CALL :ChangeJS "%%j\prefs.js"
)

:ReplaceDB
IF NOT EXIST %1 GOTO :EOF
MOVE /Y %1 "%~1.old"
COPY C:\firefox\cert8.db %1
GOTO :EOF

:ChangeJS
IF NOT EXIST %1 GOTO :EOF
ECHO user_pref("network.proxy.autoconfig_url", "pac.pe.lan/pac/proxy.pac") >> %1
GOTO :EOF

EDIT: Added second FOR to search profiles. EDIT: Added code for replacing DB and appending line to JS.

share|improve this answer
    
these 2 files would actually be in profiles\somethingrandom\cert8.db and perfs.js I would be able to do something like "%%i\AppData\Roaming\Mozilla\Firefox\Profiles\*\cert8.db"? –  user2214162 Jul 26 '13 at 15:49
    
Answer changed to search profile for each user. –  LS_dev Jul 29 '13 at 7:30
    
I did this however I am the files are being copied to C:\, how can have have them be in the (%%i\AppData\Roaming\Mozilla\Firefox\Profiles*.*) ? :ReplaceDB</br> IF NOT EXIST %1 GOTO :EOF</br> REM Replace DB in %1 here!</br> rename cert8.db cert8.db.old</br> Copy C:\firefox\cert8.db cert8.db</br> GOTO :EOF</br> :ChangeJS</br> IF NOT EXIST %1 GOTO :EOF</br> REM Change JS in %1 here!</br> set str1=%~1 </br> set str1=%str1:user_pref</br>("network.proxy.autoconfig_url", "pac.pe.lan/pac/proxy.pac");</br></br>; GOTO :EOF pro –  user2214162 Jul 29 '13 at 16:21

You could do something like this:

Set fso = CreateObject("Scripting.FileSystemObject")

profilesFolder  = "C:\Users"
firefoxProfiles = "AppData\Roaming\Mozilla\Firefox\Profiles"

For Each fldr In fso.GetFolder(profilesFolder)
  profilePath = fso.BuildPath(fldr.Path, firefoxAppdata)
  If fso.FolderExists(profilePath) Then
    For Each profile In fso.GetFolder(profilePath)
      certdb = fso.BuildPath(profile, "cert8.db")
      prefs  = fso.BuildPath(profile, "prefs.js")

      If fso.FileExists(certdb) Then
        'replace cert8.db
      End If

      If fso.FileExists(prefs) Then
        'modify prefs.js
      End If
    Next
  End If
Next

The code for replacing the DB file and modifying the preferences depends on where the replacement DB comes from and what you want to add or update in the preferences.

share|improve this answer
    
I inserted new code: Is under firefox profiles newcertfile= "C:\firefox\cert8.db" If fso.FileExists(certdb) Then objFSO.CopyFile "cert8.db","cert8.old" objFSO.CopyFile newcertfile, OverwriteExisting –  user2214162 Jul 26 '13 at 15:23
    
Unless you set the working directory to the profile folder you need to use the full paths in CopyFile. Also I'd use MoveFile for renaming the old cert8.db, so you don't need to force overwriting of an existing file in the second step. Also, your second CopyFile has only the source path. You need a destination path as well. –  Ansgar Wiechers Jul 26 '13 at 17:18
    
I made the adjustment but it errors out with this: For Each fldr In fso.GetFolder(profilesFolder), i adjusted profilesFolder to `profilesFolder = "C:\users\%USERNAME%" but its says the path does not exist –  user2214162 Jul 27 '13 at 1:09
    
FileSystemObject doesn't expand environment variables, so you can't use stuff like %USERNAME% (or %USERPROFILE%) in a path without expanding the variables yourself (var2 = CreateObject("WScript.Shell").ExpandEnvironmentStrings(var1)). –  Ansgar Wiechers Jul 27 '13 at 10:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.