We help IT Professionals succeed at work.
Get Started

Need to modify application removal script

305 Views
Last Modified: 2012-05-05
I'm using the script below to remove some apps like Groupwise and Novell Client.  I need to modify it so that when prompted with the "Do you want to uninstall" it automatically selects yes.  I don't want any user interaction with this script.  I believe I need to use the /qn switch somewhere, but I'm not sure where?
Here is the script:
Option Explicit
 
Dim strComputer, strMSI, MSIapp, App, AppToRemove, objShell
 
strComputer = "."
set objShell = CreateObject("WScript.Shell")
 
'========================================
AppToRemove = "Groupwise"
 
'
strMSI = UninstallString(AppToRemove)
If strMSI<>"" Then
      wscript.echo strMSI
      objShell.Run strMSI
End If
 
function UninstallString(strProductName)
      dim strComputer, oReg, strKeyPath, arrSubKeys, subkey, x
      Const HKEY_LOCAL_MACHINE = &H80000002
      strComputer = "."
      
      Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
 
      ' Get array of subkeys under uninstall registry entry
      strKeyPath = "SOFTWARE\microsoft\windows\currentversion\uninstall"
      oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
      
      For Each subkey In arrSubKeys
            x=FindUninstallString(subkey, strProductName)
            if x<>"" then
                  if LCase(Left(x,7))="msiexec" then
                        ' Check msiexec for parameters...
                        if InStr(1,x,"/I")>0 then x=Replace(x, "/I","/X")
                        if InStr(1,x,"/quiet")<1 then x=x & " /quiet"
                        if InStr(1,x,"/noreboot")<1 then x=x & " /noreboot"
                  end if
                  UninstallString=x
                  exit function
            end if
      Next
end function
 
function FindUninstallString(strKey, strProductName)
      dim DisplayName, Publisher, UninstallString, search
      On Error Resume Next
      DisplayName=objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & strKey & "\DisplayName")
      Publisher=objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & strKey & "\Publisher")
      UninstallString=objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & strKey & "\UninstallString")
      search = Instr(1, DisplayName, strProductName, 1)
      
      ' Get uninstall string
      if search>0 Then
            if UninstallString="" then UninstallString="MsiExec.exe /X" & strKey
            FindUninstallString = UninstallString
      end if
end function
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE