Same homepage for Firefox as for Internet Explorer

image_pdfimage_print

Sometimes each country has a different homepage. In Internet Explorer you can set each homepage via the policy. Also that can be done for Firefox in combination with GPO For Firefox. But it also generates extra administrative load as the same setting should be maintained at 2 places.

To avoid this, I made a script that reads the current Internet Explorer homepage (set via policy) and set is as the default homepage for Firefox.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
' ================================================================================================
' Sets the Firefox homedirectory to the same as Internet Explorer.
' If the default Internet Explorer homepage has not been set or the default Microsoft homepage is
' used, then about:blank will be opened.
' Also, force this setting, so the user cannot override the homepage setting to, for example, pages
' from the last session. 
' 
' Created by Willem-Jan Vroom
' Version history:
'
'   0.0.1 Initial version
' 
' ================================================================================================
 
' ------------------------------------------------------------------------------------------------
' Declare the most variables. 
' ------------------------------------------------------------------------------------------------
 
  Option Explicit
 
  Dim objShell                          : set objShell                      = CreateObject("WScript.Shell")
  Dim objNetWork                        : set objNetWork                    = CreateObject("WScript.Network")
  Dim objLogFile                        : Set objLogFile                    = CreateObject("Scripting.FileSystemObject")
  Dim objLogFileFSO                     : Set objLogFileFSO                 = CreateObject("Scripting.FileSystemObject")
  Dim objFSO                            : Set objFSO                        = CreateObject("Scripting.FileSystemObject")
  Dim objProcessEnv                     : Set objProcessEnv                 = objShell.Environment("PROCESS")
  Dim objWMIService                     : Set objWMIService                 = GetObject("winmgmts:\\.\root\cimv2")
  Dim objReg                            : Set objReg                        = GetObject("winmgmts:\\.\root\default:StdRegProv")
  Dim CurrentDir                        : CurrentDir                        = Left(Wscript.ScriptFullname, InstrRev(Wscript.ScriptFullname, "\"))
  Dim strcomputerName                   : strcomputerName                   = objProcessEnv("COMPUTERNAME")
  Dim strLogLocation                    : strLogLocation                    = "C:\WINDOWS\system32\Logfiles"
  Dim strOutputFile                     : strOutputFile                     = strLogLocation & "\" & strcomputerName & "_Set_Firefox_Homepage" & Replace(FormatDateTime(Now(), 2),"/","-") & ".log"
  Dim strArchitecture                   : strArchitecture                   = "x86"
  Dim strCurrentUser                    : strCurrentUser                    = ""
  Dim strCurrentUserSID                 : strCurrentUserSID                 = "" 
  Dim strOS                             : strOS                             = ""
  Dim strKeyPath                        : strKeyPath                        = ""
  Dim strIEStartPage                    : strIEStartPage                    = ""
  Dim strFFStartPage                    : strIEStartPage                    = ""
  Dim strCommand                        : strCommand                        = ""
  Dim strWindir                         : strWinDir                         = objShell.ExpandEnvironmentStrings("%WinDir%")
 
  Dim colItems
  Dim objItem
  Dim colComputers
  Dim objComputer
 
 
  Const ForWriting           = 2
  Const ForReading           = 1
  Const ForAppending         = 8
  Const OverWriteFiles       = True
  const HKEY_CURRENT_USER    = &H80000001
  const HKEY_LOCAL_MACHINE   = &H80000002
  Const HKEY_USERS           = &H80000003 
 
' ------------------------------------------------------------------------------------------------
' Create the log location (if not exists)
' Open the logfile.  
' ------------------------------------------------------------------------------------------------
 
  CreateFolderStructure(strLogLocation)
  OpenLogFile()
  WriteToLog "- ACTION: script started."
 
' ------------------------------------------------------------------------------------------------
' Detect the current OS.  
' ------------------------------------------------------------------------------------------------
 
  Set colItems = objWMIService.ExecQuery("Select Caption,BuildNumber from Win32_OperatingSystem")
  For Each objItem in colItems
      strOS            = objItem.Caption
      valOSBuildNumber = objItem.BuildNumber
  next
 
' ------------------------------------------------------------------------------------------------
' Find the currently logged on userid.
' And translate it to the users SID.
' ------------------------------------------------------------------------------------------------
 
  Set colComputers = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
  For Each objComputer in colComputers
      strCurrentUser= objComputer.UserName
  Next
  strCurrentUserSID = GetSIDFromUser(strCurrentUser)
 
' ------------------------------------------------------------------------------------------------
' Detect the current processor architecture.  
' ------------------------------------------------------------------------------------------------
 
  if objFSO.FolderExists(strWindir & "\syswow64") Then
     strArchitecture = "x64"
  end if  
 
  WriteToLog("########## Details regarding operating system and logged on user ##########")
  WriteToLog("Found Operating System: " & strOS)
  WriteToLog("Found architecture:     " & strArchitecture)
  WriteToLog("Logged on userid:       " & strCurrentUser)
  WriteToLog("Logged on user SID:     " & strCurrentUserSID)
 
' ------------------------------------------------------------------------------------------------
' Find the current homedir (from the current logon user)  
' It is stored in HKCU\Software\Microsoft\Internet Explorer\Main, hive ‘Start Page’
' ------------------------------------------------------------------------------------------------
 
  WriteToLog("- ACTION: Read Registry hive")
  WriteToLog("  HKEY_USERS\" & strCurrentUserSID & "\Software\Microsoft\Internet Explorer\Main")
  WriteToLog("     Hive: 'Start Page'")
  objReg.GetStringValue HKEY_USERS, strCurrentUserSID & "\Software\Microsoft\Internet Explorer\Main","Start Page",strIEStartPage
  WriteToLog("IE Start Page:          " & strIEStartPage)
 
' ------------------------------------------------------------------------------------------------
' Check if the home page starts with http://www.microsoft.com/isapi/redir.dll
' In that case the homepage for Firefox will be changed to about:blank
' ------------------------------------------------------------------------------------------------
 
  if instr(strIEStartPage, "http://www.microsoft.com/isapi/redir.dll") > 0 then
     WriteToLog("The firefox homepage will be set to about:blank as the default Internet Explorer page has already been set.")     
     strIEStartPage = "about:blank"
  end if
 
' ------------------------------------------------------------------------------------------------
' Set the Firefox homepage.
' ------------------------------------------------------------------------------------------------
 
  WriteToLog("- ACTION: Set the Firefox homepage to: " & strIEStartPage)
  objReg.CreateKey HKEY_LOCAL_MACHINE, "Software\Policies\Mozilla\lockPref"
  objReg.SetStringValue HKEY_LOCAL_MACHINE, "Software\Policies\Mozilla\lockPref", "browser.startup.homepage", strIEStartPage
  objReg.GetStringValue HKEY_LOCAL_MACHINE, "Software\Policies\Mozilla\lockPref", "browser.startup.homepage", strFFStartPage
  WriteToLog("- ACTION: Verify the Firefox homepage.")
  WriteToLog("  HKEY_LOCAL_MACHINESoftware\Policies\Mozilla\lockPref")
  WriteToLog("     Hive: 'browser.startup.homepage' has been set to " & strFFStartPage)
  WriteToLog(" ")
 
' ------------------------------------------------------------------------------------------------
' Force the use of the homepage.
' ------------------------------------------------------------------------------------------------
 
  WriteToLog("- ACTION: Force the use of the homepage " & strIEStartPage)
  objReg.SetStringValue HKEY_LOCAL_MACHINE, "Software\Policies\Mozilla\lockPref", "browser.startup.page", "1"
  objReg.GetStringValue HKEY_LOCAL_MACHINE, "Software\Policies\Mozilla\lockPref", "browser.startup.page", strFFStartPage
  WriteToLog("- ACTION: Verify the force of using the homepage.")
  WriteToLog("  HKEY_LOCAL_MACHINESoftware\Policies\Mozilla\lockPref")
  WriteToLog("     Hive: 'browser.startup.page' has been set to " & strFFStartPage)
  WriteToLog(" ")  
 
' ------------------------------------------------------------------------------------------------
' We are done!
' ------------------------------------------------------------------------------------------------
 
  CloseLogFile()
  wscript.Quit 0
 
 
Sub OpenLogFile() 
 
' ------------------------------------------------------------------------------------------------
' Subroutine: OpenLogFile() 
' The name of the logfile is mentinoed in the variabele strOutputFile.
' ------------------------------------------------------------------------------------------------
 
  If objLogFileFSO.FileExists(strOutputFile) Then
     Set objLogFile = objLogFileFSO.OpenTextFile(strOutputFile, ForWriting)
         Else
     Set objLogFile = objLogFileFSO.CreateTextFile(strOutputFile)
  End If
 
End Sub
 
Sub CloseLogFile()
 
' ------------------------------------------------------------------------------------------------
' Subroutine: CloseLogFile()
' Close the log file.
' ------------------------------------------------------------------------------------------------
 
  WriteToLog("########## End configuring Firefox          ##########")
  WriteToLog "- ACTION: script ended."
  objLogFile.Close
  Set objLogfileFSO = Nothing
 
End Sub
 
Function WriteToLog(sLogMessage)
 
' ------------------------------------------------------------------------------------------------
' Function: WriteToLog(sLogMessage)
' Writes an entry 'sLogMessage' in the logfile.
' ------------------------------------------------------------------------------------------------
 
  if instr(sLogMessage, "- ACTION: ") = 0 then sLogMessage = "          " & sLogMessage
  objLogFile.WriteLine("Time: " & now & "  " & sLogMessage)
 
End Function
 
 
Sub CreateFolderStructure(strFolderNameToBeCreated)
 
' ------------------------------------------------------------------------------------------------
' Subroutine: CreateFolderStructure(strFolderNameToBeCreated)
' Creates the map as mentioned in strFolderNameToBeCreated.
' ------------------------------------------------------------------------------------------------
 
  Dim arrFoldersTMP : arrFoldersTMP = split (strFolderNameToBeCreated,"\")
  Dim strFolder  : strFolder  = ""
  Dim objFolderTMP
 
  For Each objFolderTMP in arrFoldersTMP
      strFolder = strFolder & objFolderTMP
      If NOT objFSO.FolderExists(strFolder) Then
             objFSO.CreateFolder(strFolder)
      end If
      strFolder = strFolder & "\"
  Next
 
End Sub
 
Function GetSIDFromUser(UserName)
 
' ------------------------------------------------------------------------------------------------
' Function: GetSIDFromUser(UserName)
' Gets the SID from the give username.
' ------------------------------------------------------------------------------------------------
 
  Dim DomainName, Result, WMIUser
 
  If InStr(UserName, "\") > 0 Then
    DomainName = Mid(UserName, 1, InStr(UserName, "\") - 1)
    UserName = Mid(UserName, InStr(UserName, "\") + 1)
  Else
    DomainName = CreateObject("WScript.Network").UserDomain
  End If
 
  On Error Resume Next
  Set WMIUser = GetObject("winmgmts:{impersonationlevel=impersonate}!" _
    & "/root/cimv2:Win32_UserAccount.Domain='" & DomainName & "'" _
    & ",Name='" & UserName & "'")
  If Err.Number = 0 Then
    Result = WMIUser.SID
  Else
    Result = ""
  End If
  On Error GoTo 0
 
  GetSIDFromUser = Result
 
End Function

Permanent link to this article: https://www.vroom.cc/wordpress/same-homepage-for-firefox-as-for-internet-explorer/