Script to reset IE 8 zoom

Posted on Updated on

An old script to share :-)  It will help to fix an old problem that occurred in IE 8, if that’s even still around and in use today ;-)

'==========================================================================
' AUTHOR  : Nick Moseley
' COMMENT : This script will parse all User profiles on the computer, load their
' 	HKCU hive, then set the appropriate registry keys.
' HISTORY : 
'	1.0 (01/01/2009) - Original script
'	1.1 (04/07/2009) - Added code for default user profile
'	1.2 (06/07/2009) - Added code for writing changes to C:\Windows\Version Log.txt
'	2.0 (03/01/2010) - Added support/samples for DWORD values. Added custom
'		error codes to check for failed regkey or value creations. Added
'		a skip for svcdesktopauthclient account.
'	2.1 (05/04/2011) - FIxed the logging to not use asterisks
'==========================================================================
Option Explicit

Const ForAppending = 8
Const HKLM = &H80000002
Const sUserKey = "\Software\Microsoft\Internet Explorer\Zoom" ' Note: key must have a leading backslash
Const sDWORDValueName = "ResetZoomOnStartup2"
Const sDWORDValue = "1"

Dim oReg, oFSO, oFile, oUserSubkey, aUserProfiles, oShell
Dim sProfileLCase, sRegExe, sRegLoad, sRegUnload, sHiveName, sSubPath, sProfile, sValueName, sKeyPathUserProfiles, sValue, ReturnVal

Set oReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject ("Scripting.FileSystemObject")

'==========================================================================
' Begin log file etnries
'==========================================================================
If Not oFSO.FileExists("C:\Windows\Temp\ResetIe8zoom.log") Then
	oFSO.CreateTextFile "C:\Windows\Temp\ResetIe8zoom.log"
End If
Set oFile = oFSO.OpenTextFile ("C:\Windows\Temp\ResetIe8zoom.log", ForAppending, True)

oFile.WriteLine "Configuration of user settings for IE 8 Reset Zoom Level"
oFile.WriteLine "  => Began at " & Date & " " & Time
oFile.WriteLine "  => For each user profile, set " & sDWORDValueName & " (string) to " & sDWORDValue & " in HKCU" & sUserKey
'==========================================================================


' Begin configuration of existing user profiles
sValueName = "ProfileImagePath"
sKeyPathUserProfiles = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
sRegExe = "C:\Windows\system32\reg.exe"

oReg.EnumKey HKLM, sKeyPathUserProfiles, aUserProfiles

' Existing User Profiles
For Each oUserSubkey In aUserProfiles
    sSubPath = sKeyPathUserProfiles & "\" & oUserSubkey
    oReg.GetExpandedStringValue HKLM,sSubPath,sValueName,sValue
  
    sProfile = Split(sValue, "\")
    sProfileLCase = LCase(sProfile(2))
  
    If sProfileLCase = "system32" Then
    	oFile.WriteLine "  => Skipped user profile: system32"
    ElseIf sProfileLCase = "localservice" Then
    	oFile.WriteLine "  => Skipped user profile: localservice"
    ElseIf sProfileLCase = "networkservice" Then
    	oFile.WriteLine "  => Skipped user profile: networkservice"
    ElseIf sProfileLCase = "serviceprofiles" Then
    	oFile.WriteLine "  => Skipped user profile: serviceprofiles"
    ElseIf sProfileLCase = "svcdesktopauthclient" Then
    	oFile.WriteLine "  => Skipped user profile: svcdesktopauthclient"
    Else
    	sHiveName = "TempHive_" & sProfileLCase
    
    	' Load user's profile hive into a temp location
    	sRegLoad = " LOAD HKLM\" & sHiveName & " """ & sValue & "\ntuser.dat"""
    	oShell.Run sRegExe & sRegLoad, 0, True
    
    	' Call subroutine to change registry key
    	SetConfigUserHive (sHiveName)
		oFile.WriteLine "  => Set user profile: " & sProfileLCase
    
    	' Unload user's profile hive
    	sRegUnload = " UNLOAD HKLM\" & sHiveName
    	oShell.Run sRegExe & sRegUnload, 0, True
    End If  
Next

' Default User Profile
sHiveName = "TempHive_DefaultUser"
sRegLoad = " LOAD HKLM\" & sHiveName & " ""C:\Users\Default\ntuser.dat"""
oShell.Run sRegExe & sRegLoad, 0, True
SetConfigUserHive (sHiveName)
oFile.WriteLine "  => Set user profile: Default User"
sRegUnload = " UNLOAD HKLM\" & sHiveName
oShell.Run sRegExe & sRegUnload, 0, True

' End logging
oFile.WriteLine "  => Completed at " & Date & " " & Time
WScript.Quit (oFile.Close)

Sub SetConfigUserHive (sTempHive)
	Dim sTempHiveKeyPath

	' Path of registry keys
	sTempHiveKeyPath = sTempHive & sUserKey

	' Create registry key if the value doesn't already exist
	If oReg.GetDWORDValue(HKLM, sTempHiveKeyPath & "\", sDWORDValueName) <> 0 Then
		ReturnVal = oReg.CreateKey(HKLM, sTempHiveKeyPath)
	End If

	' Create DWORD Value
	ReturnVal = oReg.SetDWORDValue(HKLM, sTempHiveKeyPath & "\", sDWORDValueName, sDWORDValue)
End Sub



Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s