Friday, July 13, 2012

Manage Firefox via Group Policy

Actually this heading is misleading. There is no proper easy to use  Active Directory Group Policy Object for Firefox yet.  This one shows a  a simple solution that will propogate firefox settings in to client machines via a logon script written in VB Script. Compared to some solutions this one is very simple and can be completed with in a very short time.

When a user logged in , logon scrpt given below will copy a file called user.js to that user's firefox profile folder.  User Firefox profile folder is usually located under :  C:\Documents and Settings\<username>\Application Data\Mozilla\Firefox\Profiles

You can include many default settings in this user.js file such as user home page , proxy settings and switch off or set annoying settings such as checking for default browser etc    ... that you would like to deploy in to multiple machines in the domain. Syntax of the user.js file is exactly similar to the prefs.js file that lives in the firefox profile folder.

Difference between these two files is that settings in the user.js file take precedence over the settings in the  prefs.js file and user.js file can contain subset of preferences stored in the  prefs.js file.
Here's how its done.

1. Create the user.js file with all the necessary settings you would like to be propagated in to client machines. Sample user.js file is shown below.

# Mozilla User Preferences
/* Do not edit this file.
 *
 * If you make changes to this file while the application is running,
 * the changes will be overwritten when the application exits.
 *
 * To make a manual change to preferences, you can visit the URL about:config
 * For more information, see http://www.mozilla.org/unix/customizing.html#prefs
 */
user_pref("browser.startup.homepage", "http://www.mycompany.com");
user_pref("browser.shell.checkDefaultBrowser", false);

2. Create a VB Script file (Ex: MyFile.vbs ) with following code in it  


Option Explicit
dim oShell

dim LastDate
dim filesys
dim profilePath
dim latestProfileFolder
Dim fso
dim fldr
dim MainFolder
dim sourceFile
dim targetFile
dim boolOverWrite

Set oShell = CreateObject("WScript.Shell")

Set fso = CreateObject("Scripting.FileSystemObject")

profilePath = oShell.ExpandEnvironmentStrings("%APPDATA%") & "\Mozilla\Firefox\Profiles"
' If firefox directory doesnt exist , then gracefully exit
If fso.FolderExists(profilePath) Then
Set MainFolder = fso.GetFolder(profilePath)
For Each fldr In MainFolder.SubFolders
    If fldr.DateLastModified > LastDate Or IsNull(LastDate) Then
        latestProfileFolder = fldr.Name
        LastDate = fldr.DateLastModified
    End If
Next

If latestProfileFolder <> "" Then
  profilePath = profilePath & "\" & latestProfileFolder
End If

sourceFile = "\\<Your Server Share>\Firefox\user.js"
targetFile = profilePath & "\user.js"

'WScript.Echo targetFile 
If fso.FileExists(targetFile ) Then
boolOverWrite = vbTrue
fso.CopyFile sourceFile, targetFile, boolOverWrite
Else
boolOverWrite = vbFalse
fso.CopyFile sourceFile, targetFile, boolOverWrite
End If
End If

3. Copy both files in to a shared location that has read access to all domain users.

4. Setup a group policy object so that this vbscript runs during the user logon

Refs:
Prefs.js file - MozillaZine Knowledge Base

No comments:

Post a Comment