'Harlan Brumm, Product Support Technical Lead Revit Architecture - Product Support 'Autodesk, Inc. 2010 'This Script is designed to Uninstall Revit 2011 products cleanly from your computer. See http://usa.autodesk.com/adsk/servlet/ps/dl/item?siteID=123112&id=14633513&linkID=9243099 Option Explicit 'On Error Resume Next DIM strComputer DIM regLogonUserName DIM objShell DIM LogonUserName DIM objFLO DIM strProgram1 DIM strProgram2 DIM strProgram3 DIM strProgram4 DIM strHKEY1 DIM strHKEY2 DIM strHKEY3 DIM strHKEY4 DIM strHKEY5 DIM strKeyPath DIM arrSubkeys DIM strSubkey DIM oReg DIM oShell DIM oFSO Dim UninstallString DIM ProductCode DIM colItems DIM objWMIService DIM objItem DIM strKeyPath1 DIM subkey1 DIM arrSubKeys1 DIM filesys DIM objRegistry DIM ProductCode64bit DIM ProductCode32bit DIM regRevit DIM RevitVersion DIM strStart DIM strTitle DIM intStart DIM WshNetwork DIM bar, i DIM strAreSure DIM strTitleAreSure DIM intAreSure DIM strScrFin DIM strScrFinTitle DIM intfin DIM strUnComp DIM strUnCompTitle DIM intUnComp DIM strNoRevit DIM strNoRevitTitle DIM intNoRevit DIM strProgram5 DIM fname DIM RevitName DIM RevitShortName DIM RevitApp Const HKEY_CURRENT_USER = &H80000001 Const HKEY_LOCAL_MACHINE = &H80000002 'Setting up Presets strComputer = "." 'Startup the Script strStart = "WARNING! This script will remove Autodesk Revit 2011 products Please backup any custom family or template files prior to running this script. Run this Script as an Adminstrator. This Script removes Autodesk Revit 2011 products and deletes folders and Registry Keys from your computer. Do You Wish to Continue?" strTitle = "Cleanly Uninstall Autodesk Revit 2011 products" intStart = msgbox(strStart,vbYesNo+VBExclamation,strTitle) If intStart = vbYes Then Do fname = inputbox("Enter the Name of Revit product to Uninstall. Type either: Architecture, Structure, or MEP below. Only one product can be removed at a time.") If fname = "Architecture" then Wscript.Echo "Autodesk Revit Architecture 2011 will be uninstalled" RevitName = "Autodesk Revit Architecture 2011" RevitApp = "RAC 2011" RevitShortName = "Revit Architecture 2011" ProductCode64bit = "{94D463D0-2B13-4181-9512-B27004B1151A}" ProductCode32bit = "{4AF99FCA-1D0C-4D5A-9BFE-0D4376A52B23}" Exit Do ElseIf fname = "Structure" then Wscript.Echo "Autodesk Revit Structure 2011 will be Uninstalled" RevitName = "Autodesk Revit Structure 2011" RevitApp = "RST 2011" RevitShortName = "Revit Structure 2011" ProductCode64bit = "{23853368-22DD-4817-904B-DB04ADE9B0C8}" ProductCode32bit = "{0EE1FCA9-7474-4143-8F22-E7AD998FACBF}" Exit Do ElseIf fname = "MEP" then Wscript.Echo "Autodesk Revit MEP 2011 will be Uninstalled" RevitName = "Autodesk Revit MEP 2011" RevitApp = "RME 2011" RevitShortName = "Revit MEP 2011" ProductCode64bit = "{C31F3560-0007-4955-9F65-75CB47F82DB5}" ProductCode32bit = "{CCCB80C8-5CC5-4EB7-89D0-F18E405F18F9}" Exit Do ElseIf fname = "" then Wscript.Quit Else Wscript.Echo "Product Not Recongized. Try again." End If Loop 'Determine Login UserName Set WshNetwork = WScript.CreateObject("WScript.Network") LogonUserName = WshNetwork.UserName 'WScript.Echo "Current User Name: " & LogonUserName 'Determine if Revit.exe exists for Revit 2011 Set filesys = CreateObject("Scripting.FileSystemObject") If filesys.FileExists ("C:\Program Files\Autodesk\" & RevitShortName & "\Program\Revit.exe") Then 'Wscript.Echo "Autodesk Revit Architecture 2011 is Installed. Will proceed with the Clean Uninstall" Else strNoRevit = "Autodesk " & RevitShortName & " is NOT Installed. This Script is to be run when " & RevitName & " is Installed." strNoRevitTitle = RevitName & " Not Installed" intNoRevit = msgbox(strNoRevit,vbOkOnly+VBExclamation,strNoRevitTitle) Wscript.Quit End If 'Determine 64 bit Revit or Not regRevit = "HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\Revit\" & RevitName & "\Components\ProductName" Set objShell = WScript.CreateObject("WScript.Shell") RevitVersion = objShell.RegRead(regRevit) 'WScript.Echo "This machine is running " & RevitVersion 'Verifying Vista or XP and set Default Folders and Keys Set objFLO = CreateObject("Scripting.FileSystemObject") If objFLO.FolderExists ("C:\Users") Then 'WScript.Echo "Windows 7 or Windows Vista Program Paths" strProgram1 = "C:\Program Files\Autodesk\" & RevitShortName strProgram2 = "C:\ProgramData\Autodesk\" & RevitApp strProgram3 = "C:\Users\" & LogonUserName & "\AppData\Local\Autodesk\Revit\" & RevitName strProgram4 = "C:\Users\" & LogonUserName & "\AppData\Roaming\Autodesk\Revit\2011" 'WScript.Echo "Windows 7 or Windows Vista RegKeys" strHKEY1 = "Software\Autodesk\Revit\" & RevitName ' HKEY_CURRENT_USER strHKEY2 = "SOFTWARE\Autodesk\" & RevitApp 'HKEY_LOCAL_MACHINE strHKEY3 = "SOFTWARE\Autodesk\Revit\2011"'HKEY_LOCAL_MACHINE strHKEY4 = "SOFTWARE\Autodesk\Revit\" & RevitName 'HKEY_LOCAL_MACHINE strHKEY5 = "Software\Autodesk\Revit\2011" ' HKEY_CURRENT_USER Else 'WScript.Echo "Windows XP Program Paths" strProgram1 = "C:\Program Files\Autodesk\" & RevitShortName strProgram2 = "C:\Documents and Settings\" & LogonUserName & "\Application Data\Autodesk\REVIT\2011" strProgram3 = "C:\Documents and Settings\" & LogonUserName & "\Local Settings\Application Data\Autodesk\Revit\" & RevitName strProgram4 = "C:\Documents and Settings\All Users\Application Data\Autodesk\" & RevitApp 'WScript.Echo "Windows XP RegKeys" strHKEY1 = "Software\Autodesk\Revit\" & RevitName ' HKEY_CURRENT_USER strHKEY2 = "SOFTWARE\Autodesk\" & RevitApp 'HKEY_LOCAL_MACHINE strHKEY3 = "SOFTWARE\Autodesk\Revit\2011"'HKEY_LOCAL_MACHINE strHKEY4 = "SOFTWARE\Autodesk\Revit\" & RevitName 'HKEY_LOCAL_MACHINE strHKEY5 = "Software\Autodesk\Revit\2011" ' HKEY_CURRENT_USER End If 'Uninstalling Autodesk Revit Architecture 2011 x64 '******************************** strAreSure = "Starting to Uninstall " & RevitName & ". This may take a few minutes and the progress bar may pause during the process. Are you Sure you wish to Continue?" strTitleAreSure = "Are you sure you want to Continue?" intAreSure = MsgBox(strAreSure,vbYesNo+VBExclamation,strTitleAreSure) If intAreSure = vbYes Then 'Launching the Progress Bar Set bar = new IEProgBar With bar .Move -1, -1, 500, -1 .Units = 30 .Show 'Starting to move the bar For i = 0 to 7 WScript.Sleep 500 .Advance Next 'Determine Product Code based on 64 bit version of Revit If RevitVersion = RevitName & " x64" then ProductCode = ProductCode64bit Else ProductCode = ProductCode32bit End if '******************************** ' Get scripting objects needed throughout uninstall. Set oShell = CreateObject("WScript.Shell") '************************** UninstallString = "MsiExec.exe /X" & ProductCode & " /qn" & " /norestart" Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ strComputer & "\root\default:StdRegProv") strKeyPath1 = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath1, arrSubKeys1 'Updating the Progress bar movement For i = 8 to 20 WScript.Sleep 250 .Advance Next For Each subkey1 In arrSubKeys1 IF subkey1 = ProductCode Then oShell.Run UninstallString, 1, True End If Next 'Finishing the Progress Bar For i = 21 to 29 WScript.Sleep 250 .Advance Next End With Set bar = Nothing Set oShell = Nothing Set oReg = Nothing strUnComp = "Uninstall of " & RevitName & " Complete. Now, other folders and registry keys will be removed. This may take a few minutes and the progress bar may pause during the process." strUnCompTitle = "Uninstall of " & RevitName & " Complete" intUnComp = msgbox(strUnComp,vbOkonly+vbInformation,strUnCompTitle) '************* End Section ************ 'Uninstall is complete, proceed to deleting folders and reg keys for clean uninstall 'Delete 1st Folder 'Launch new Progress Bar Set bar = new IEProgBar With bar .Move -1, -1, 500, -1 .Units = 30 .Show For i = 0 to 10 WScript.Sleep 100 .Advance Next Set filesys = CreateObject("Scripting.FileSystemObject") If filesys.FolderExists (strProgram1) Then filesys.DeleteFolder strProgram1, True 'WScript.Echo "Folder " & strProgram1 & " deleted" Else 'Wscript.Echo "Folder " & strProgram1 & " does not Exist" End If 'Delete 2nd Folder If filesys.FolderExists (strProgram2) Then filesys.DeleteFolder strProgram2, True 'WScript.Echo "Folder " & strProgram2 & " deleted" Else 'Wscript.Echo "Folder " & strProgram2 & " does not Exist" End If 'Delete 3rd folder If filesys.FolderExists (strProgram3) Then filesys.DeleteFolder strProgram3, True 'WScript.Echo "Folder " & strProgram3 & " deleted" Else 'Wscript.Echo "Folder " & strProgram3 & " does not Exist" End If 'moving the bar 'Delete 4th folder If filesys.FolderExists (strProgram4) Then filesys.DeleteFolder strProgram4, True 'WScript.Echo "Folder " & strProgram4 & " deleted" Else 'Wscript.Echo "Folder " &strProgram4 & " does not Exist" End If 'Move progress Bar For i = 11 to 20 WScript.Sleep 100 .Advance Next 'Delete Registry Key strHKEY1 - HKEY_CURRENT_USER strKeyPath = strHKEY1 Set objRegistry = GetObject("winmgmts:\\" & _ strComputer & "\root\default:StdRegProv") 'WScript.Echo "Deleting RegKEY " & strHKEY1 DeleteSubkeys HKEY_CURRENT_USER, strKeypath 'Delete Registry Key strHKEY2 - HKEY_LOCAL_MACHINE strKeyPath = strHKEY2 Set objRegistry = GetObject("winmgmts:\\" & _ strComputer & "\root\default:StdRegProv") 'WScript.Echo "Deleting RegKEY " & strHKEY2 DeleteSubkeys HKEY_LOCAL_MACHINE, strKeypath 'Delete Registry Key strHKEY3 - HKEY_LOCAL_MACHINE strKeyPath = strHKEY3 Set objRegistry = GetObject("winmgmts:\\" & _ strComputer & "\root\default:StdRegProv") 'WScript.Echo "Deleting RegKEY " & strHKEY3 DeleteSubkeys HKEY_LOCAL_MACHINE, strKeypath 'Delete Registry Key strHKEY4 - HKEY_LOCAL_MACHINE strKeyPath = strHKEY4 Set objRegistry = GetObject("winmgmts:\\" & _ strComputer & "\root\default:StdRegProv") 'WScript.Echo "Deleting RegKEY " & strHKEY4 DeleteSubkeys HKEY_LOCAL_MACHINE, strKeypath 'Delete Registry Key strHKEY5 - HKEY_CURRENT_USER strKeyPath = strHKEY5 Set objRegistry = GetObject("winmgmts:\\" & _ strComputer & "\root\default:StdRegProv") 'WScript.Echo "Deleting RegKEY " & strHKEY5 DeleteSubkeys HKEY_CURRENT_USER, strKeypath 'moving the bar For i = 21 to 30 WScript.Sleep 100 .Advance Next End With Set bar = Nothing Sub DeleteSubkeys(HKEY_CURRENT_USER, strKeyPath) objRegistry.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubkeys If IsArray(arrSubkeys) Then For Each strSubkey In arrSubkeys DeleteSubkeys HKEY_CURRENT_USER, strKeyPath & "\" & strSubkey Next End If objRegistry.DeleteKey HKEY_CURRENT_USER, strKeyPath End Sub 'Finish Script strScrFin = "Clean Uninstall Complete. " & RevitName & " has been cleanly removed from your computer. " & RevitName & " can now be reinstalled" strScrFinTitle = "Clean Uninstall Complete" intfin = msgbox(strScrFin,vbOkonly+vbInformation,strScrFinTitle) Else strScrFin = "Clean Uninstall of Autodesk Revit 2011 products has been canceled." strScrFinTitle = "Clean Uninstall Canceled" intfin = msgbox(strScrFin,vbOkonly+vbInformation,strScrFinTitle) End If Else strScrFin = "Clean Uninstall of Autodesk Revit 2011 products has been canceled." strScrFinTitle = "Clean Uninstall Canceled" intfin = msgbox(strScrFin,vbOkonly+vbInformation,strScrFinTitle) End If ' VBScript to display a progress bar ' ------------------------------------------------------------------' '-------- Start Progress bar Class ---------------------------------- Class IEProgBar Private FSO, IE, BCol, TCol, ProgCol, ProgNum, ProgCaption, Pic, Q2, sTemp, iProg, ProgTitle Private Sub Class_Initialize() On Error Resume Next Set FSO = CreateObject("Scripting.FileSystemObject") sTemp = FSO.GetSpecialFolder(2) Set IE = CreateObject("InternetExplorer.Application") With IE .AddressBar = False .menubar = False .ToolBar = False .StatusBar = False .width = 400 .height = 180 .resizable = True End With BCol = "E0E0E4" '--background color. TCol = "000000" '--caption text color. ProgCol = "0000A0" '--progress color. ProgNum = 19 'number of progress units. ProgCaption = "Uninstalling Autodesk Revit 2011 product..." ProgTitle = "Uninstall Progress" Q2 = chr(34) iProg = 0 '--to track progress. End Sub Private Sub Class_Terminate() On Error Resume Next IE.Quit Set IE = Nothing Set FSO = Nothing End Sub Public Sub Show() Dim s, i, TS On Error Resume Next s = "" & ProgTitle & "" s = s & "" If (Pic <> "") Then s = s & "" End If If (ProgCaption <> "") Then s = s & "" _ & ProgCaption & "

" Else s = s & "
" End If s = s & "
" For i = 1 to ProgNum s = s & "
" Next s = s & "


" Set TS = FSO.CreateTextFile(sTemp & "\iebar1.html", True) TS.Write s TS.Close Set TS = Nothing IE.Navigate "file:///" & sTemp & "\iebar1.html" IE.visible = True End Sub '-- Advance method colors one progress unit. ' iProg variable tracks how many '-- units have been colored. ' Each progress unit is a with ID="P". They can be '-- accessed in sequence through Document.All.Item. Public Sub Advance() On Error Resume Next If (iProg < ProgNum) and (IE.Visible = True) Then IE.Document.All.Item("P", (iProg)).bgcolor = Q2 & "#" _ & ProgCol & Q2 iProg = iProg + 1 End If End Sub '--resize and/or position window. Use -1 For any value Not being Set. Public Sub Move(PixLeft, PixTop, PixWidth, PixHeight) On Error Resume Next If (PixLeft > -1) Then IE.Left = PixLeft If (PixTop > -1) Then IE.Top = PixTop If (PixWidth > 0) Then IE.Width = PixWidth If (PixHeight > 0) Then IE.Height = PixHeight End Sub '--remove Registry settings that display advertising in the IE title bar. '-- This change won't show up the first time it's used because the IE '-- instance has already been created when the method is called. Public Sub CleanIETitle() Dim sR1, sR2, SH On Error Resume Next sR1 = "HKLM\Software\Microsoft\Internet Explorer\Main\Window Title" sR2 = "HKCU\Software\Microsoft\Internet Explorer\Main\Window Title" Set SH = CreateObject("WScript.Shell") SH.RegWrite sR1, "", "REG_SZ" SH.RegWrite sR2, "", "REG_SZ" Set SH = Nothing End Sub '------------- Set background color: --------------------- Public Property Let BackColor(sCol) If (TestColor(sCol) = True) Then BCol = sCol End Property '------------- Set caption color: --------------------- Public Property Let TextColor(sCol) If (TestColor(sCol) = True) Then TCol = sCol End Property '------------- Set progress color: --------------------- Public Property Let ProgressColor(sCol) If (TestColor(sCol) = True) Then ProgCol = sCol End Property '------------- Set icon: --------------------- Public Property Let Icon(sPath) If (FSO.FileExists(sPath) = True) Then Pic = sPath End Property '------------- Set title text: --------------------- Public Property Let Title(sCap) ProgTitle = sCap End Property '------------- Set caption text: --------------------- Public Property Let Caption(sCap) ProgCaption = sCap End Property '------------- Set number of progress units: --------------------- Public Property Let Units(iNum) ProgNum = iNum End Property '--confirm that color variables are valid 6-character hex color codes: '-- If Not 6 characters Then TestColor = False '-- If any character is Not 0-9 or A-F Then TestColor = False Private Function TestColor(Col6) Dim iB, sB, iB2, Boo1 On Error Resume Next TestColor = False If (Len(Col6) <> 6) Then Exit Function For iB = 1 to 6 sB = Mid(Col6, iB, 1) iB2 = Asc(UCase(sB)) If ((iB2 > 47) and (iB2 < 58)) or ((iB2 > 64) and (iB2 < 71)) Then Boo1 = True Else Boo1 = False Exit For End If Next If (Boo1 = True) Then TestColor = True End Function End Class