posted by 범벙이 2012. 9. 5. 14:42
#Include <Array.au3>
#Include <File.au3>
 
; Check if Mozilla Firefox x86 version is installed
If @OSArch = "X86" Then
    $MozillaFirefoxCurrentVersion = RegRead("HKLM\SOFTWARE\Mozilla\Mozilla Firefox", "CurrentVersion")
    $MozillaFirefoxInstallDirectory = RegRead("HKLM\SOFTWARE\Mozilla\Mozilla Firefox\" & $MozillaFirefoxCurrentVersion & "\Main", "Install Directory")
EndIf
If @OSArch = "X64" Then
    $MozillaFirefoxCurrentVersion = RegRead("HKLM\SOFTWARE\Wow6432Node\Mozilla\Mozilla Firefox", "CurrentVersion")
    $MozillaFirefoxInstallDirectory = RegRead("HKLM\SOFTWARE\Wow6432Node\Mozilla\Mozilla Firefox\" & $MozillaFirefoxCurrentVersion & "\Main", "Install Directory")
EndIf
$MozillaFirefoxExecutableFile = FileExists($MozillaFirefoxInstallDirectory & "\firefox.exe")
If $MozillaFirefoxExecutableFile = 0 Then
        MsgBox(0x40010, @ScriptName, "Mozilla Firefox is not installed! Please install it and then run this script!", 4)
        Exit
EndIf
 
; Find Mozilla Firefox profile folder
If FileExists(@AppDataDir & "\Mozilla\Firefox\profiles.ini") Then
    $Mozilla_Firefox_profile_folder = IniRead(@AppDataDir & "\Mozilla\Firefox\profiles.ini", "Profile0", "Path", "")
        $Mozilla_Firefox_profile_folder = StringReplace($Mozilla_Firefox_profile_folder, "/", "\")
EndIf
 
; EDIT MOZILLA FIREFOX PREFERENCES FILE
$InputFile = @AppDataDir & "\Mozilla\Firefox\" & $Mozilla_Firefox_profile_folder & "\prefs.js"
; String to find
$StringToFind = '"browser.startup.homepage"'
; New home page address
$HomePageAddress = "" ; write the desired home page address (inside quotes), for example: http://www.google.com/
; Delete the current home page address
Global $Array
_FileReadToArray ($InputFile, $Array)
$Array = _DeleteHomePageAddress ($Array, $StringToFind)
_FileWriteFromArray ($InputFile, $Array, 1)
; Write a new home page address
$File = FileOpen($InputFile, 257) ; UTF8 encoding without BOM
FileWriteLine($File, 'user_pref("browser.startup.homepage", ' & '"' & $HomePageAddress & '"' & ');')
FileClose($File)
 
Func _DeleteHomePageAddress ($Array, $StringToFind)
    Local $Item
    For $Element In $Array
        If StringInstr ($Element, $StringToFind) <> 0 Then
            _ArrayDelete ($Array, $Item)
        Else
            $Item+=1
        EndIf
    Next
    Return ($Array)
EndFunc