better product code extraction

This commit is contained in:
2022-10-24 14:19:00 -04:00
parent eaf0afa2b5
commit c2c8c23d2b
+9 -2
View File
@@ -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 ) {