Last active
December 10, 2015 21:28
-
-
Save williamjacksn/4494971 to your computer and use it in GitHub Desktop.
Update the Firefox DisplayName in the Add/Remove Programs list to indicate whether Firefox is on the "esr" release channel.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' This script will try to detect what update channel Firefox is using. If the | |
' update channel is "esr" then the DisplayName in the Add/Remove Programs list | |
' will be updated to inclued an "[esr]" tag at the end. | |
' If the update channel is "release" and there is an "[esr]" tag in the | |
' DisplayName, the tag will be removed. | |
' by William Jackson (w@utexas.edu) | |
Set shell = WScript.CreateObject("WScript.Shell") | |
logPrefix = "Firefox ESR detection script: " | |
shell.LogEvent Information, logPrefix & "Starting." | |
const HKLM = &H80000002 | |
fxInstalled = False | |
' Get the operating system architecture. This script works on both 32- and | |
' 64-bit versions of Windows, but only attempts to detect 32-bit versions of | |
' Firefox. | |
For Each os In GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem") | |
arch = os.OSArchitecture | |
Next | |
shell.LogEvent Information, logPrefix & "OS architecture: " & arch | |
If arch = "32-bit" Then | |
uninstall = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | |
Else | |
uninstall = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | |
End If | |
shell.LogEvent Information, logPrefix & "Registry key for installed programs: " & uninstall | |
Set reg = GetObject("winmgmts:\\.\root\default:StdRegProv") | |
reg.EnumKey HKLM, uninstall, installedProducts | |
For Each installedProduct In installedProducts | |
If InStr(installedProduct, "Mozilla Firefox") > 0 Then | |
fxInstalled = True | |
fxUninstallPath = uninstall & "\" & installedProduct | |
shell.LogEvent Information, logPrefix & "Firefox found in registry at: " & fxUninstallPath | |
reg.GetStringValue HKLM, fxUninstallPath, "DisplayName", fxDisplayName | |
shell.LogEvent Information, logPrefix & "Current Firefox DisplayName: " & fxDisplayName | |
reg.GetStringValue HKLM, fxUninstallPath, "InstallLocation", pathToFirefox | |
shell.LogEvent Information, logPrefix & "Firefox install location: " & pathToFirefox | |
Exit For | |
End If | |
Next | |
If Not fxInstalled Then | |
shell.LogEvent Information, logPrefix & "Did not find Firefox installed. Stopping." | |
WScript.Quit | |
End If | |
' If we made it this far, Firefox appears to be installed. | |
channel = "unknown" | |
channelFilePath = pathToFirefox & "\defaults\pref\channel-prefs.js" | |
shell.LogEvent Information, logPrefix & "Checking for update channel in: " & channelFilePath | |
Set fso = CreateObject("Scripting.FileSystemObject") | |
Set channelFile = fso.OpenTextFile(channelFilePath) | |
Do Until channelFile.AtEndOfStream | |
text = channelFile.ReadLine | |
If InStr(text, "pref(""app.update.channel"", ") > 0 Then | |
text = Right(text, Len(text) - InStr(text, ",")) | |
text = Right(text, Len(text) - InStr(text, """")) | |
channel = Left(text, InStr(text, """") - 1) | |
shell.LogEvent Information, logPrefix & "Update channel appears to be: " & channel | |
Exit Do | |
End If | |
Loop | |
channelFile.Close | |
Select Case channel | |
Case "esr" | |
If InStr(fxDisplayName, "[esr]") > 0 Then | |
' DisplayName has already been altered | |
shell.LogEvent Information, logPrefix & "Update channel is ""esr"" but DisplayName has already been updated." | |
Else | |
' Firefox is on esr channel but DisplayName does not indicate that | |
newFxDisplayName = fxDisplayName & " [esr]" | |
shell.LogEvent Information, logPrefix & "Update channel is ""esr"", changing DisplayName to: " & newFxDisplayName | |
reg.SetStringValue HKLM, fxUninstallPath, "DisplayName", newFxDisplayName | |
End If | |
Case "release" | |
If InStr(fxDisplayName, "[esr]") > 0 Then | |
' Firefox is on release channel but DisplayName is wrong | |
newFxDisplayName = Left(fxDisplayName, Len(fxDisplayName) - 6) | |
shell.LogEvent Information, logPrefix & "Update channel is ""release"", changing DisplayName to: " & newFxDisplayName | |
reg.SetStringValue HKLM, fxUninstallPath, "DisplayName", newFxDisplayName | |
End If | |
Case Else | |
shell.LogEvent Information, logPrefix & "Not doing anything with this update channel." | |
End Select | |
shell.LogEvent Information, logPrefix & "Stopping." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment