/build/static/layout/Breadcrumb_cap_w.png
03/10/2019 118 views

When i install Visual studio it is creating uninstall registry with different hive each time.

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\ddd4bb47

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\2237a22

I need to find registry hive and need to add NoRemove=1

Please help me to correct this script

Set-ExecutionPolicy Unrestricted -Force

Set-Location "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"

Get-ChildItem | Where-Object { $_.DisplayName -eq "2237a22" } | New-Item NoRemove=1




1 Comment   [ + ] Show comment

Comments

  • You need to recurse through each hive and examine the DisplayName for your product, then write the key.

    Its a bit trick because you need to expand each item value for the DisplayName. But also handle the hive items which error, because the there is no item to expand.

    It's not as easy as you would think.

All Answers

1

Here is something I knocked together, need to handle the "Select-Object : Property "DisplayName" cannot be found." errors, but its a good start.

$UninstallRegistryArray = (Get-ChildItem HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall).Name -replace 'HKEY_LOCAL_MACHINE','HKLM:'
Foreach ($Uninstall in $UninstallRegistryArray)
    {If ((Get-ItemProperty -Path $Uninstall | Select-Object -ExpandProperty 'DisplayName') -eq 'Name of App')
         {Write-Output 'Found the key! Do your command here to write your key.'}}
Answered 03/10/2019 by: rileyz
Red Belt