better product code extraction
This commit is contained in:
+9
-2
@@ -4,6 +4,13 @@
|
||||
$UNINSTALL_KEYS = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
|
||||
$UNINSTALL_KEYS += Get-ChildItem -Path HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
|
||||
|
||||
Function Get-GUIDFromMSIUninstallString {
|
||||
param([string]$str)
|
||||
$start = $str.IndexOf('{') + 1
|
||||
$end = $str.IndexOf('}')
|
||||
Return $str.Substring($start, $end - $start)
|
||||
}
|
||||
|
||||
Foreach ( $reg in $UNINSTALL_KEYS ) {
|
||||
## Get the uninstall key
|
||||
$REG_PROPERTY = Get-ItemProperty -Path $reg.PSPath
|
||||
@@ -19,10 +26,10 @@ Foreach ( $reg in $UNINSTALL_KEYS ) {
|
||||
If ( $REG_PROPERTY.InstallLocation ) { $INSTALL_LOCATION = $REG_PROPERTY.InstallLocation }
|
||||
|
||||
## Get the product code from the UninstallString
|
||||
If ( $REG_PROPERTY.UninstallString ) { $PRODUCT_CODE = $REG_PROPERTY.UninstallString.Replace('MsiExec.exe /X','') }
|
||||
If ( $REG_PROPERTY.UninstallString ) { $PRODUCT_CODE = $(Get-GUIDFromMSIUninstallString -str $REG_PROPERTY.UninstallString) }
|
||||
|
||||
## Get the product code from the ModifyPath
|
||||
ElseIf ( $REG_PROPERTY.ModifyPath ) { $PRODUCT_CODE = $REG_PROPERTY.ModifyPath.Replace('MsiExec.exe /X','') }
|
||||
ElseIf ( $REG_PROPERTY.ModifyPath ) { $PRODUCT_CODE = $(Get-GUIDFromMSIUninstallString -str $REG_PROPERTY.ModifyPath) }
|
||||
|
||||
## Uninstall the app
|
||||
If ( $PRODUCT_CODE ) {
|
||||
|
||||
Reference in New Issue
Block a user