0

I'm trying to uninstall a software using this code

$path = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{Product-cod-1}"

function Uninstall_SW {
    Write-Host "Starting Uninstallation.."
    if(Test-Path $path) {
        $uninstallStr = (Get-ItemProperty -Path $path).UninstallString
        if($uninstallStr) {
            Write-Host "Uninstalling SW command: $uninstallStr"
            Start-Process -FilePath "cmd.exe" ArgumentList "/c $uninstallStr /qn" -Wait -NoNewWindow
            Write-Host "Uninstall Complete"
        } else {
                Write-Host "No uninstall str found"
        } else {
               Write-Host "Registry Path not found $path"
        }
    }

}

Unistall_SW

Now this work perfectly fine when I run locally on my laptop. But when this is deployed to Microsoft SCCM and on running this script in Software center, it fails to uninstall the software as it does not find the Registry Path and I have confirmed that the registry path is correct.

is there something I'm missing?

Note: Also tried with uninstall using get-package and uninstall package, but that does not work either

3
  • If the SCCM client is 32-bit, then if it looks for HKLM\SOFTWARE Windows will automatically redirect it to HKLM\SOFTWARE\WOW6432Node due to registry redirection. Commented Jul 23, 2024 at 17:57
  • Uninstall-package only works for msi installs. If it's installed as one user, the system user won't see it. Commented Jul 23, 2024 at 18:12
  • Even though the SCCM client is 64Bit, Bill_Stewart is probably still on the right track, because all legacy programs are executed as 32bit Processes. So if you use an application make sure the 64bit checkbox is checked, if it is indeed a programm fix this by not calling powershell.exe but C:\Windows\sysnative\WindowsPowerShell\v1.0\powershell.exe in your program which will force windows to use a 64bit powershell scripting host. (the folder sysnative does not exist that is a hardlink or something that is only created for 32bit processes but you can test it, it will work) Commented Jul 24, 2024 at 14:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.