/build/static/layout/Breadcrumb_cap_w.png

VB Script to uninstall MSI using Display Name

hi

i am trying to run the below vb script to uninstall msi (x64/x86) using "DISPLAY NAME" in windows 7 (x64) but looks like the below script doesn't like the DISPLAY NAME called (Pulse Secure). But if i change the name of DISPLAY NAME to "Pulse Sec" or "Secure Pulse" etc. it works fine. So i am just thinking to see why it doesn't like "Pulse Secure" name?

any help should be appreciated
'~$~----------------------------------------~$~
Option Explicit
const HKEY_LOCAL_MACHINE = &H80000002

Dim objWshShell, objWMI, WinDir, RegExp, objFSO, objFile, outFile
Dim colWin32_ComputerSystem, objWin32_ComputerSystem
Dim strSoftwareName, strApplicationType
Dim strSystemType, strProgramFiles, strSoftwareRegistryKey
Set objFSO=CreateObject("Scripting.FileSystemObject")

'outFile="c:\Amfam\Logs\MyRA\VBS.inf"
'Set objFile = objFSO.CreateTextFile(outFile,True)
'objFile.Write "Uninstall Started" & vbCrLf


Set objWshShell = WScript.CreateObject("WScript.Shell")
Set objWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
WinDir = objWshShell.ExpandEnvironmentStrings("%windir%")
Set RegExp = new RegExp
RegExp.IgnoreCase = true


'On Error Resume Next


strSystemType = "x32"
Set colWin32_ComputerSystem = objWMI.ExecQuery ("Select * from Win32_ComputerSystem")
For Each objWin32_ComputerSystem in colWin32_ComputerSystem
If objWin32_ComputerSystem.SystemType = "x64-based PC" Then
strSystemType = "x64"
'objFile.Write "strSystemType = x64" & vbCrLf
End If
Next

SetApplicationPathItems "32-bit"
SetApplicationPathItems "64-bit"

RemoveCurrentInstalls "Pulse Secure"

Wscript.Quit





' ~$~----------------------------------------~$~
'        STANDARD FUNCTIONS & SUBROUTINES
' ~$~----------------------------------------~$~
Sub SetApplicationPathItems(strAppType)
'Setting the path to the correct ""Program Files"" folder and ""SOFTWARE"" registry key based on the application and OS type
strApplicationType = strAppType
If strSystemType = "x64" Then
If strApplicationType = "64-bit" Then
strSoftwareRegistryKey = "SOFTWARE"
If UCase(Wscript.FullName) = UCase(WinDir & "\SysWOW64\WScript.exe") Then
'Installing a 64-bit application on a 64-bit OS from a 32-bit wscript.exe process
strProgramFiles = objWshShell.ExpandEnvironmentStrings("%ProgramW6432%")
'objFile.Write "%ProgramW6432%" & vbCrLf
Else
'Installing a 64-bit application on a 64-bit OS from a 64-bit wscript.exe process
strProgramFiles = objWshShell.ExpandEnvironmentStrings("%ProgramFiles%")
'objFile.Write "%ProgramFiles%" & vbCrLf
End If
Else
strSoftwareRegistryKey = "SOFTWARE\Wow6432Node"
'Installing a 32-bit application on a 64-bit OS (the wscript.exe process type does not matter)
strProgramFiles = objWshShell.ExpandEnvironmentStrings("%ProgramFiles(x86)%")
'objFile.Write "%ProgramFiles(x86)%" & vbCrLf
End If
Else
strSoftwareRegistryKey = "SOFTWARE"
'Installing a 32-bit application on a 32-bit OS from a 32-bit wscript.exe process
strProgramFiles = objWshShell.ExpandEnvironmentStrings("%ProgramFiles%")
'objFile.Write "%ProgramFiles%" & vbCrLf
End If
End Sub

' ~$~----------------------------------------~$~
Sub RemoveCurrentInstalls(strValueCheck)
Dim objReg, strKeyPath, subkey, arrSubKeys, strValue, strCheckKey, intArrayCount, arrUninstallString, x
Dim strUninstallString, intStringLength, intUninstallReturn
strUninstallString = ""
arrUninstallString = Array()
intArrayCount = 0
strKeyPath = strSoftwareRegistryKey & "\Microsoft\Windows\CurrentVersion\Uninstall"
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
strValue = ""
strCheckKey = strKeyPath & "\" & subkey
objReg.GetStringValue HKEY_LOCAL_MACHINE,strCheckKey,"DisplayName",strValue
If Not IsNull(strValue) Then
RegExp.pattern = strValueCheck
If (RegExp.test (strValue) = TRUE) Then
' Attempts to obtain the UninstallString for the matching string.
objReg.GetStringValue HKEY_LOCAL_MACHINE,strCheckKey,"UninstallString",strValue
reDim preserve arrUninstallString(UBound(arrUninstallString) +1)
arrUninstallString(intArrayCount) = strValue
intArrayCount = intArrayCount + 1
End If
End If
Next
For x = LBound(arrUninstallString) to UBound(arrUninstallString)
strUninstallString = arrUninstallString(x)
If UCase(Left(strUninstallString, 14)) = UCase("MsiExec.exe /I") Then
'Adjusting the uninstall string to fix known oddities
intStringLength = Len(strUninstallString)
strUninstallString = Left(strUninstallString, 13) & "X " & Right(strUninstallString, intStringLength - 14)
End If
intUninstallReturn = objWshShell.Run (strUninstallString & " /qb-! /log C:\PulseSecure-Uninst-MSI.log /norestart", 1, True)
Next
End Sub
'~$~----------------------------------------~$~

0 Comments   [ + ] Show comments

Answers (4)

Posted by: anonymous_9363 8 years ago
Red Belt
1
I know I said I retired but I was here, had time, so....

Phil's right, use the WI object model.

As an exercise, though, o come to the problem, I think the issue is with your use of the Regular Expression object. Using that is fine and all when you're dealing with unknown or variable return values but here, you know what you're expecting back so why not do a simple case-less string and string length match? In pseudo-code:

If input_string_length matches registry_string_return_length then
If input_string matches registry_string_return then
'// Bingo! Uninstall it
Endif
Endif

 
Posted by: anonymous_9363 8 years ago
Red Belt
1
PS:

Please apply the 'Code' style to your code. It makes the post more manageable.
Posted by: Pressanykey 8 years ago
Red Belt
0
Hi,
why not just use the Windows Installer API via COM (if your language is vbs)?
It's allot less convoluted and you do not need to worry about 32/64 bit as you'll be de-installing using the product code..

Phil
Posted by: KVB 8 years ago
Senior White Belt
0
I can only assume you're scanning the ARP keys for Pulse because you can't trust what the product code is going to be. I am also in a project to deploy PulseSecure and recently discovered what I consider a very odd behavior. The product codes change mid install depending on what region the installer detects. So far I am aware of 16 different product codes for 8 different regions. Obviously, 1 for each OS architecture. Pulse has suggested they will release these product codes in one of their next Release Notes. I would offer the ones up that I have, but I have no idea what version you're dealing with, so they might be totally irrelevant. Their support is actually quite helpful when engaged, they only took about 45 minutes to produce the codes when I started seeing issues with global deployments.

Comments:
  • I should also state that I dealt with the multiple product codes by placing them in an ini and having my install\uninstall script cycle through them in a list. SCCM on the other hand was a PITA as it required 16 unique detection methods. I have a good reason for wanting the prod code for this VPN client rather than relying on the exe versions alone. - KVB 8 years ago
    • I had a similar problem with an InstallShield "wrapped" MSI, that changed the ProductCode dynamically, always, regardless :-O

      I completely repackaged that in the end... (I know you should never repackage an MSI, but I did not consider that a MSI ;-) ) - Pressanykey 8 years ago

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ