By
Carm01
All,
I have decided to release my code for the automated clean install, set up and configuration of Mozilla Firefox with a Mozilla.cfg file included in my example as well. I seen an older version of this and decided to post mine on here. This is Windows 10 friendly.
The whole process once compiled executes in about 15 seconds on my machine from start to finish as it is extremely fast.
If you want to include your own Mozilla.cfg into the mix simply place Your Mozilla.cfg file in the same directory as the exe when it is run. If you do not wish to embed the Mozilla.cfg file into the script as a back up in case you forget you need to remove that line of code to embed it.
I hope this helps some people esp those wanting to understand how to use a cfg file to set default settings for all users without having to do it by putting all those files and folders in the defaultapp data folders.
#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Clear-App-firefox.ico
#AutoIt3Wrapper_Outfile=FirefoxUpdater(x64Stable)_x.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_Comment=Preformes a clean install of Firefox 64bit Stable version. Auto downloads latest version.
#AutoIt3Wrapper_Res_Description=Updates to the Latest 64bit Stable
#AutoIt3Wrapper_Res_Fileversion=2.5.0.0
#AutoIt3Wrapper_Res_ProductVersion=2.5.0.0
#AutoIt3Wrapper_Res_Language=1033
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <InetConstants.au3>
#include <EventLog.au3>
#include <Inet.au3>
#include <File.au3>
#include <array.au3>
#include <Misc.au3>
#include <TrayConstants.au3> ; Required for the $TRAY_CHECKED and $TRAY_ICONSTATE_SHOW constants.
If UBound(ProcessList(@ScriptName)) > 2 Then Exit
TraySetToolTip("Firefox Updater")
HotKeySet("^!m", "MyExit") ; ctrl+Alt+m kills program ( hotkey )
Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode.
Opt("TrayOnEventMode", 1) ; Enable TrayOnEventMode.
TrayCreateItem("About")
TrayItemSetOnEvent(-1, "About")
TrayCreateItem("") ; Create a separator line.
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "ExitScript")
TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "About") ; Display the About MsgBox when the tray icon is double clicked on with the primary mouse button.
TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu.
Local $sVersion, $CVersion, $ecode
;https://www.mozilla.org/en-US/firefox/developer/all/
;https://www.mozilla.org/en-US/firefox/all/#
;https://www.mozilla.org/en-US/firefox/all/#en-US
;https://www.mozilla.org/en-US/firefox/beta/all/#en-US
;https://archive.mozilla.org/pub/firefox/candidates/48.0b1-candidates/build2/
;https://archive.mozilla.org/pub/firefox/candidates/
getfiles()
compare()
killapps()
uninstall()
dlinstall()
Exit
Func killapps()
; kill firefox and plugin if running
If FileExists("C:\Program Files\Mozilla Firefox\") Then
$cmd = "taskkill.exe /im firefox.exe /f /t"
RunWait('"' & @ComSpec & '" /c ' & $cmd, @SystemDir, @SW_HIDE)
Sleep(300)
$cmd = "taskkill.exe /im plugin* /f /t"
RunWait('"' & @ComSpec & '" /c ' & $cmd, @SystemDir, @SW_HIDE)
Sleep(300)
Call("remcfg64")
EndIf
If FileExists("C:\Program Files (x86)\Mozilla Firefox\") Then
$cmd = "taskkill.exe /im firefox.exe /f /t"
RunWait('"' & @ComSpec & '" /c ' & $cmd, @SystemDir, @SW_HIDE)
Sleep(300)
$cmd = "taskkill.exe /im plugin* /f /t"
RunWait('"' & @ComSpec & '" /c ' & $cmd, @SystemDir, @SW_HIDE)
Sleep(300)
Call("remcfg32")
EndIf
EndFunc ;==>killapps
Func remcfg64()
; delete existing config file if exist
$SSlist = _FileListToArrayRec("C:\Program Files\Mozilla Firefox\", "*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH)
For $i = 1 To UBound($SSlist) - 1
If StringInStr($SSlist[$i], "mozilla.cfg") > 1 Then
FileDelete($SSlist[$i])
ElseIf StringInStr($SSlist[$i], "override.ini") > 1 Then
FileDelete($SSlist[$i])
ElseIf StringInStr($SSlist[$i], "local-settings.js") > 1 Then
FileDelete($SSlist[$i])
EndIf
Next
EndFunc ;==>remcfg64
Func remcfg32()
$SSlist = _FileListToArrayRec("C:\Program Files (x86)\Mozilla Firefox\", "*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH)
For $i = 1 To UBound($SSlist) - 1
If StringInStr($SSlist[$i], "mozilla.cfg") > 1 Then
FileDelete($SSlist[$i])
ElseIf StringInStr($SSlist[$i], "override.ini") > 1 Then
FileDelete($SSlist[$i])
ElseIf StringInStr($SSlist[$i], "local-settings.js") > 1 Then
FileDelete($SSlist[$i])
EndIf
Next
EndFunc ;==>remcfg32
Func uninstall()
; uninstall existing Firefox
If FileExists("C:\Program Files\Mozilla Firefox\Firefox.exe") Then
ShellExecuteWait("helper.exe", " /S", "C:\Program Files\Mozilla Firefox\uninstall")
EndIf
If FileExists("C:\Program Files (x86)\Mozilla Firefox\Firefox.exe") Then
ShellExecuteWait("helper.exe", " /S", "C:\Program Files (x86)\Mozilla Firefox\uninstall")
EndIf
Sleep(1500)
DirRemove("C:\Program Files (x86)\Mozilla Firefox\", 1)
DirRemove("C:\Program Files\Mozilla Firefox\", 1)
EndFunc ;==>uninstall
Func getfiles()
; get latest download
Local $sTxt, $sTxt1
$xjs = "C:\windows\temp\xjs.tmp"
$xjs1 = "C:\windows\temp\xjs1.tmp"
;$sSite = "https://www.mozilla.org/en-US/firefox/beta/all/"
$sSite = "https://www.mozilla.org/en-US/firefox/all/"
;$sNotes = "https://www.mozilla.org/en-US/firefox/beta/notes/"
$sNotes = "https://www.mozilla.org/en-US/firefox/notes/"
SplashTextOn("Progress", "", 210, 75, -1, -1, 18, "Tahoma", 10)
ControlSetText("Progress", "", "Static1", "Initializing", 2)
$source = _INetGetSource($sSite)
$sTxt = StringSplit($source, @LF)
$q = 0
$i = 0
For $i = 1 To UBound($sTxt) - 1 ; is like saying read the line number
;GUIGetMsg();prevent high cpu usage
If StringInStr($sTxt[$i], "=win64&lang=en-US") > 1 Then
$sActiveX1 = StringSplit($sTxt[$i], 'href="', 1)
$sActiveX2 = StringSplit($sActiveX1[2], '"')
Global $dia = $sActiveX2[1]
$q = 1
EndIf
If UBound($sTxt) - 1 = $i Then
$ecode = '404'
EventLog()
Exit
EndIf
If $q = 1 Then
ExitLoop
EndIf
Next
; FIND VERSION
$source = _INetGetSource($sNotes)
$sTxt1 = StringSplit($source, @LF)
$q = 0
$i = 0
For $i = 1 To UBound($sTxt1) - 1 ; is like saying read the line number
;GUIGetMsg();prevent high cpu usage
If StringInStr($sTxt1[$i], "<title>Firefox") > 1 Then
$sActiveX1 = StringSplit($sTxt1[$i], '<title>Firefox', 1)
$sActiveX2 = StringSplit($sActiveX1[2], ',')
$sVersion = StringStripWS($sActiveX2[1], 3)
$q = 1
EndIf
If $sVersion = "" Then ; error correcting if mozilla changes page where version notes are located.
$sVersion = "Current Version"
EndIf
If $q = 1 Then
ExitLoop
EndIf
Next
SplashOff()
EndFunc ;==>getfiles
Func dlinstall()
; download and install
$Version = $sVersion & " - 64 bit"
_webDownloader($dia, "FFInstall.exe", $Version)
SplashTextOn("Progress", "", 210, 75, -1, -1, 18, "Tahoma", 10)
ControlSetText("Progress", "", "Static1", "Installing Version " & $sVersion, 2)
ShellExecuteWait("FFInstall.exe", " -ms", "C:\Windows\Temp\")
If FileExists(@ScriptDir & "\mozilla.cfg") Then
FileCopy(@ScriptDir & "\mozilla.cfg", "C:\Program Files\Mozilla Firefox\mozilla.cfg", 1)
Else
FileInstall("G:\Users\username\Documents\Project\FirefoxDefault\mozilla.cfg", "C:\Program Files\Mozilla Firefox\mozilla.cfg", 1)
EndIf
FileWrite("C:\Program Files\Mozilla Firefox\defaults\pref\local-settings.js", 'pref("general.config.obscure_value", 0);' & @CRLF & 'pref("general.config.filename", "mozilla.cfg");' & @CRLF)
FileWrite("C:\Program Files\Mozilla Firefox\browser\override.ini", '[XRE]' & @CRLF & 'EnableProfileMigrator=false' & @CRLF)
FileDelete("C:\windows\temp\" & "\FFInstall.exe")
$CVersion = FileGetVersion('C:\Program Files\Mozilla Firefox\firefox.exe', $FV_PRODUCTVERSION)
SplashOff()
EndFunc ;==>dlinstall
Func _webDownloader($sSourceURL, $sTargetName, $sVisibleName, $sTargetDir = "C:\windows\temp", $bProgressOff = True, $iEndMsgTime = 2000, $sDownloaderTitle = "Mozilla Firefox")
; Declare some general vars
Local $iMBbytes = 1048576
; If the target directory doesn't exist -> create the dir
If Not FileExists($sTargetDir) Then DirCreate($sTargetDir)
; Get download and target info
Local $sTargetPath = $sTargetDir & "\" & $sTargetName
Local $iFileSize = InetGetSize($sSourceURL)
Local $hFileDownload = InetGet($sSourceURL, $sTargetPath, $INET_LOCALCACHE, $INET_DOWNLOADBACKGROUND)
; Show progress UI
ProgressOn($sDownloaderTitle, "" & $sVisibleName)
GUISetFont(8, 400)
; Keep checking until download completed
Do
Sleep(250)
; Set vars
Local $iDLPercentage = Round(InetGetInfo($hFileDownload, $INET_DOWNLOADREAD) * 100 / $iFileSize, 0)
Local $iDLBytes = Round(InetGetInfo($hFileDownload, $INET_DOWNLOADREAD) / $iMBbytes, 2)
Local $iDLTotalBytes = Round($iFileSize / $iMBbytes, 2)
; Update progress UI
If IsNumber($iDLBytes) And $iDLBytes >= 0 Then
ProgressSet($iDLPercentage, $iDLPercentage & "% - Downloaded " & $iDLBytes & " MB of " & $iDLTotalBytes & " MB")
Else
ProgressSet(0, "Downloading '" & $sVisibleName & "'")
EndIf
Until InetGetInfo($hFileDownload, $INET_DOWNLOADCOMPLETE)
; If the download was successfull, return the target location
If InetGetInfo($hFileDownload, $INET_DOWNLOADSUCCESS) Then
ProgressSet(100, "Downloading '" & $sVisibleName & "' completed")
If $bProgressOff Then
Sleep($iEndMsgTime)
ProgressOff()
EndIf
Return $sTargetPath
; If the download failed, set @error and return False
Else
Local $errorCode = InetGetInfo($hFileDownload, $INET_DOWNLOADERROR)
ProgressSet(0, "Downloading '" & $sVisibleName & "' failed." & @CRLF & "Error code: " & $errorCode)
If $bProgressOff Then
Sleep($iEndMsgTime)
ProgressOff()
EndIf
SetError(1, $errorCode, False)
FileDelete("C:\windows\temp\" & "\FFInstall.exe")
SplashOff()
EndIf
EndFunc ;==>_webDownloader
Func compare()
$CVersion = FileGetVersion('C:\Program Files\Mozilla Firefox\firefox.exe', $FV_PRODUCTVERSION)
If $sVersion = $CVersion Then
$ecode = '411'
MsgBox(64, "Firefox says:", 'You have the latest version ' & $CVersion , 5)
EventLog()
Exit
EndIf
EndFunc ;==>compare
Func EventLog()
If $ecode = '404' Then
Local $hEventLog, $aData[4] = [0, 4, 0, 4]
$hEventLog = _EventLog__Open("", "Application")
_EventLog__Report($hEventLog, 1, 0, 404, @UserName, @UserName & ' No "exe" found for Mozilla Firefox. The webpage and/or download link might have changed. ' & @CRLF, $aData)
_EventLog__Close($hEventLog)
EndIf
If $ecode = '411' Then
Local $hEventLog, $aData[4] = [0, 4, 1, 1]
$hEventLog = _EventLog__Open("", "Application")
_EventLog__Report($hEventLog, 0, 0, 411, @UserName, @UserName & " Mozilla Firefox " & "version " & $CVersion & " successfully installed." & @CRLF, $aData)
_EventLog__Close($hEventLog)
EndIf
EndFunc ;==>EventLog
Func MyExit()
Exit
EndFunc ;==>MyExit
Func About()
; Display a message box about the AutoIt version and installation path of the AutoIt executable.
MsgBox($MB_SYSTEMMODAL, "", "Firefox Update Tool" & @CRLF & @CRLF & _
"Version: 2.5.0.0" & @CRLF & _
"Firefox Updater by Carm0@Sourceforge" & @CRLF & "CTRL+ALT+m to kill", 5) ; Find the folder of a full path.
EndFunc ;==>About
Func ExitScript()
Exit
EndFunc ;==>ExitScript
#comments-start
http://superuser.com/questions/823530/change-some-default-settings-for-firefox-globally
http://mxr.mozilla.org/mozilla-release/source/browser/app/profile/firefox.js#387
http://smallbusiness.chron.com/change-default-homepage-users-54727.html
https://developer.mozilla.org/en-US/Firefox/Enterprise_deployment
https://mike.kaply.com/2012/03/16/customizing-firefox-autoconfig-files/
https://wiki.mozilla.org/Installer:Command_Line_Arguments
https://support.mozilla.org/en-US/questions/971189
http://forums.mozillazine.org/viewtopic.php?p=2228066
http://forums.mozillazine.org/viewtopic.php?f=38&t=2950829 ; updates auto
http://forums.mozillazine.org/viewtopic.php?f=8&t=2753795
http://superuser.com/questions/697018/how-to-disable-popups-in-firefox-without-add-ons
http://www.itninja.com/blog/view/deploy-popup-allowed-sites-with-firefox deploy with certain opous enabled
#ce
Mozilla.cfg file:
//
pref("browser.search.geoSpecificDefaults", false);
pref("browser.search.defaultenginename.US", "data:text/plain,browser.search.defaultenginename.US=Google");
//https://support.mozilla.org/en-US/questions/1034136
// set Firefox Default homepage
defaultPref("browser.startup.homepage", "data:text/plain,browser.startup.homepage=https://www.startpage.com/do/mypage.pl?prf=381c658b828c3fe50ec7563137fef98f");
// Don't show WhatsNew on first run after every update
pref("browser.startup.homepage_override.mstone","ignore");
// disables the 'know your rights' button from displaying on first run
pref("browser.rights.3.shown", true);
pref("browser.usedOnWindows10", true);
pref("browser.rights.override", true);
// Do not perform system default browser check on startup
pref("browser.shell.checkDefaultBrowser", false);
// set all plugins to always activated - two settings
pref("plugin.default.state", 2);
// https://support.mozilla.org/en-US/questions/982143 reference about click to play flash
// set flash and silverlight always ask = 1 always activate = 2
defaultPref("plugin.state.flash", 2);
// hide choose what i share which pops up at the bottom after a minute
lockPref("datareporting.policy.dataSubmissionPolicyBypassNotification", true);
// https://groups.google.com/forum/#!topic/mozilla.support.firefox/DRXvfTA6Hnc
//disable the "Improve Firefox" suggestion
pref("toolkit.telemetry.prompted", 2);
//https://support.mozilla.org/en-US/questions/898549
// do not block popups - can only be default or locked pref
defaultPref("dom.disable_open_during_load", false);
//http://superuser.com/questions/697018/how-to-disable-popups-in-firefox-without-add-ons
//lockpref("privacy.sanitize.migrateFx3Prefs", true);
// http://www.pcc-services.com/kixtart/firefox-lockdown.html
//pref("browser.privatebrowsing.autostart", true);
// prevent reader view from popping down at the top
pref("reader.parse-on-load.enabled",false);
// click to play - disabled so you are not prompted - https://support.mozilla.org/en-US/questions/934809
pref("plugins.click_to_play", false);
// below will set the cache only to clear on exit, you need to tell it what to do with the reset of the data not just cache leave cache out. Just add a '\\' to whatever you want to clear on browser exit.
//defaultPref("privacy.clearOnShutdown.cookies", false);
defaultPref("privacy.clearOnShutdown.downloads", false);
defaultPref("privacy.clearOnShutdown.formdata", false);
defaultPref("privacy.clearOnShutdown.history", false);
defaultPref("privacy.clearOnShutdown.sessions", false);
defaultPref("privacy.sanitize.migrateClearSavedPwdsOnExit", false);
defaultPref("privacy.sanitize.sanitizeOnShutdown", true);
//pref("browser.privatebrowsing.autostart", true);
//prevent autoplay https://support.mozilla.org/en-US/questions/1103127
//defaultPref("media.autoplay.enabled", false);
//https://wiki.mozilla.org/Electrolysis
//pref("browser.tabs.remote.autostart", true);
//pref("browser.tabs.remote.force-enable", true);
// ref: http://www.itninja.com/question/firefox-22-for-enterprise-deployment-default-preferences
// Prevent refresh message showing at the bottom if firefox is not used in a while - http://techdows.com/2016/05/firefox-reinstall-to-prompt-for-a-refresh.html https://support.mozilla.org/en-US/questions/1084402
pref("browser.disableResetPrompt", true);
// disable plugin check - https://support.mozilla.org/en-US/questions/968056
//defaultPref("plugin.scan.plid.all",false);
//defaultPref("plugins.update.url","");
// disable remember preferences
//defaultPref("signon.rememberSignons", false);
//https://twitter.com/HighTechDad/status/955916813178691584
//https://t.co/YTvSy9EBJ1
// defaultPref can also be lockPref
defaultPref("privacy.donottrackheader.enabled", true);
//defaultPref("privacy.trackingprotection.enabled", true);
lockPref("privacy.trackingprotection.introCount", 20);