Scripting Automatic Uninstall of Internet Explorer 10 and 11






I had to find a way of rolling back a bunch of Windows 7 workstations to Internet Explorer 9, due to a vendor’s specified supported platform. I thought scripting  an automatic uninstall via Group Policy to remove the Internet Explorer 10 and 11 KB updates on logon would be the best way to do this.

The requirements for this were:

  • Automatic silent un-installation
  • If a user manually upgrades Internet Explorer, automatically running again to remove the update
  • Some basic output for troubleshooting
  • Ignores 64bit OS-es

Below is the batch script I wrote, which checks the registry keys to find the installed version of Internet Explorer, and then if found, issues the relevant uninstall command. It writes a couple of files locally to check if it’s been run before, and keeps a time stamped log on a central file share of each action taken against each machine.

Also, used the Microsoft ADM templates as part of the same policy to prevent automatic redeployment of IE 10 and IE 11 via Windows Updates:

Toolkit to Disable Automatic Delivery of Internet Explorer 11
http://www.microsoft.com/en-au/download/details.aspx?id=40722

Toolkit to Disable Automatic Delivery of Internet Explorer 10
http://www.microsoft.com/en-us/download/details.aspx?id=36512

The script will check through the registry for the value of two registry keys which contain the current version number of Internet Explorer:
HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Version
HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\SvcVersion

Once the version number is determined, the appropriate action is taken:

  • Version 11: Silently issue uninstall of KB2841134​, rolling the computer back to IE9
  • Version 10: Silently issue uninstall of KB2718695, rolling the computer back to IE9
  • Version 9: No action taken, script logs an exit & the values matched
  • Version 8: As above. WSUS will push out IE9 to this machine if it hasn’t done already

The script also writes some text files to a local directory, under C:\TEMP\. The script uses these files as flags to determine if it needs to run again or not.

If a previously uninstalled V10 or V11 is upgraded again, the script should detect this and reset these flags.

Because of the way Internet Explorer updates apply, expected behaviour of this is as follows (assuming a user has just installed IE11 manually):

  • User logs on, already has V9 installed. Script runs & detects no action is required
  • User installs IE10 or IE11. Reboot is required to finalise installation (if user does not reboot, they will have IE10 / IE11 for the duration of this session)
  • User reboots computer
  • Windows presents ‘Configuring updates’ on shutdown & again on start-up to apply IE10 / IE11
  • Computer presents CTRL+ALT+DEL. Script runs, detects & uninstalls upgraded IE10 / IE11
  • When the user logs back in, they will have IE10 or IE11 available to them, however it has already been uninstalled (just not applied via Windows Updates yet)
  • User reboots
  • Windows presents ‘Configuring updates’ on shutdown & again on start-up to apply IE9
  • Computer presents CTRL+ALT+DEL. Script runs and detects IE9 installed and no action required
  • User logs in, and is presented with IE9
setlocal ENABLEEXTENSIONS

REM Set current date & time
for /f "tokens=1-3 delims=/- " %%a in ('date /t') do set XDate=%%a-%%b-%%c 
for /f "tokens=1-2 delims=: " %%a in ('time /t') do set XTime=%%a.%%b 

IF NOT EXIST "C:\TEMP" (MKDIR C:\TEMP\)

Echo Beginning script @ %XDate% %XTime% on machine %COMPUTERNAME% >> \\SERVERNAME\IEScripts\%COMPUTERNAME%.txt


:OSTest
IF EXIST "%PROGRAMFILES(X86)%" (GOTO 64BIT) ELSE (GOTO 32BIT)


:64BIT
Echo 64Bit OS detected, exiting.. >> \\SERVERNAME\IEScripts\%COMPUTERNAME%.txt
exit


:32BIT
Echo 32Bit OS detected, continuing... >> \\SERVERNAME\IEScripts\%COMPUTERNAME%.txt
 

:CHECKVER
REM Checking HKLM\Software\Microsoft\Internet Explorer\Version key value and setting versionNumber value

set "KEY_NAME=HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer"
set "VALUE_NAME=Version"
For /F "tokens=2*" %%A IN ('REG QUERY "%KEY_NAME%" /v "%VALUE_NAME%"') Do (
 set "versionNumber=%%B"
)
for /f "delims=." %%a in ("%versionNumber%") do set "versionNumber=%%a"
Echo Internet Explorer v%versionNumber% detected in reg key 'VERSION'>> \\SERVERNAME\IEScripts\%COMPUTERNAME%.txt


:CHECKVER1
REM Checking HKLM\Software\Microsoft\Internet Explorer\SvcVersion key value and setting versionNumber1 value

set "KEY_NAME=HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer"
set "VALUE_NAME=svcVersion"
For /F "tokens=2*" %%A IN ('REG QUERY "%KEY_NAME%" /v "%VALUE_NAME%"') Do (
 set "versionNumber1=%%B"
)
for /f "delims=." %%a in ("%versionNumber1%") do set "versionNumber1=%%a"
Echo Internet Explorer v%versionNumber1% detected in reg key 'SVCVERSION' >> \\SERVERNAME\IEScripts\%COMPUTERNAME%.txt

:CHECKER
REM Checks if previous uninstallation has been reverted. If so, deletes .txt flags from computer to allow script to run again. If registry returns 8 or 9 for either value & the .txt file exists, file will exit.
if %versionNumber1% GEQ 11 del C:\Temp\IE*.txt
if %versionNumber% GEQ 11 del C:\Temp\IE*.txt
if %versionNumber1% GEQ 10 del C:\Temp\IE*.txt
if %versionNumber% GEQ 10 del C:\Temp\IE*.txt
IF EXIST "C:\TEMP\IE8.txt" GOTO EOF
IF EXIST "C:\TEMP\IE9.txt" GOTO EOF
IF EXIST "C:\TEMP\IE10.txt" GOTO V9
IF EXIST "C:\TEMP\IE11.txt" GOTO V10


:V11
REM Set date & Time, then issue uninstall commands if VERSION or SVCVERSION values are 11

for /f "tokens=1-3 delims=/- " %%a in ('date /t') do set XDate=%%a-%%b-%%c 
for /f "tokens=1-2 delims=: " %%a in ('time /t') do set XTime=%%a.%%b

if %versionNumber1% GEQ 11 wusa /uninstall /KB:2841134 /quiet /norestart
if %versionNumber1% GEQ 11 Echo %XDate% %XTime% Issued uninstall of KB2841134 (IE v11) due to VALUE_NAME=SVCVERSION=%versionNumber1% >> \\SERVERNAME\IEScripts\%COMPUTERNAME%.txt

if %versionNumber% GEQ 11 wusa /uninstall /KB:2841134 /quiet /norestart
if %versionNumber% GEQ 11 Echo %XDate% %XTime% Issued uninstall of KB2841134 (IE v11) due to VALUE_NAME=Version=%versionNumber% >> \\SERVERNAME\IEScripts\%COMPUTERNAME%.txt

if %versionNumber1% GEQ 11 Echo %XDate% %XTime% Issued uninstall of IE v11. Please check \\SERVERNAME\iescripts\%computername%.txt for verbose logging >> C:\TEMP\IE11.txt
if %versionNumber% GEQ 11 Echo %XDate% %XTime% Issued uninstall of IE v11. Please check \\SERVERNAME\iescripts\%computername%.txt for verbose logging >> C:\TEMP\IE11.txt

if %versionNumber1% GEQ 11 GOTO EOF
if %versionNumber% GEQ 11 GOTO EOF


:V10
REM Set date & Time, then issue uninstall commands if VERSION or SVCVERSION values are 10

for /f "tokens=1-3 delims=/- " %%a in ('date /t') do set XDate=%%a-%%b-%%c 
for /f "tokens=1-2 delims=: " %%a in ('time /t') do set XTime=%%a.%%b

if %versionNumber1% GEQ 10 wusa /uninstall /KB:2718695 /quiet /norestart
if %versionNumber1% GEQ 10 Echo %XDate% %XTime% Issued uninstall of KB2718695 (IE v10) due to VALUE_NAME=SVCVERSION=%versionNumber1% >> \\SERVERNAME\IEScripts\%COMPUTERNAME%.txt

if %versionNumber% GEQ 10 wusa /uninstall /KB:2718695 /quiet /norestart
if %versionNumber% GEQ 10 Echo %XDate% %XTime% Issued uninstall of KB2718695 (IE v10) due to VALUE_NAME=Version=%versionNumber% >> \\SERVERNAME\IEScripts\%COMPUTERNAME%.txt

if %versionNumber1% GEQ 10 Echo %XDate% %XTime% Issued uninstall of IE v10. Please check \\SERVERNAME\iescripts\%computername%.txt for verbose logging >> C:\TEMP\IE10.txt
if %versionNumber% GEQ 10 Echo %XDate% %XTime% Issued uninstall of IE v10. Please check \\SERVERNAME\iescripts\%computername%.txt for verbose logging >> C:\TEMP\IE10.txt

if %versionNumber1% GEQ 10 GOTO EOF
if %versionNumber% GEQ 10 GOTO EOF


:V9
REM If version 9 is detected by this point, log and exit
if %versionNumber1% GEQ 9 Echo v%versionNumber1% detected - exiting without changes. VALUE_NAME=SvcVersion=%versionNumber1%. Please check \\SERVERNAME\iescripts\%computername%.txt for verbose logging >> C:\TEMP\IE9.txt
if %versionNumber% GEQ 9 GOTO EOF

:V8

REM If version 8 is detected by this point, log and exit
Please check \\SERVERNAME\iescripts\%computername%.txt for verbose logging >> C:\TEMP\IE8.txt
if %versionNumber% GEQ 8 GOTO EOF

:EOF
for /f "tokens=1-3 delims=/- " %%a in ('date /t') do set XDate=%%a-%%b-%%c
for /f "tokens=1-2 delims=: " %%a in ('time /t') do set XTime=%%a.%%b
Echo Finished script @ %XDate% %XTime% >> \\SERVERNAME\IEScripts\%COMPUTERNAME%.txt
Echo ====================================================================================== >> \\SERVERNAME\IEScripts\%COMPUTERNAME%.txt
exit

 





This entry was posted in Batch, Group Policy and tagged , , . Bookmark the permalink.

Leave a Reply