# Script to uninstall non Win32 program for all profile users

**URL:** <https://forums.powershell.org/t/script-to-uninstall-non-win32-program-for-all-profile-users/23221>\
**Category:** PowerShell Help\
**Created:** [November 27, 2023, 8:26am UTC](https://forums.powershell.org/t/script-to-uninstall-non-win32-program-for-all-profile-users/23221 "2023-11-27T08:26:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giannis46](https://avatars.discourse-cdn.com/v4/letter/g/d07c76/32.png) [@Giannis46](https://forums.powershell.org/u/Giannis46)\
**Post date:** [November 27, 2023, 8:26am UTC](https://forums.powershell.org/t/script-to-uninstall-non-win32-program-for-all-profile-users/23221/1 "2023-11-27T08:26:06Z")

</div>

I am trying to uninstall a non Win32 app with the following code:

```auto
$appName = "my_non_Win32_app"
$user = $env:USERNAME

$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location -Path $scriptPath

Write-Output "Script Initialization..."

function Get-App {

    param(
        [Parameter(Mandatory=$true)]
        [string]$Name
        )

    # Get application GUID

    $app = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* `
    -ErrorAction SilentlyContinue | `
    Where-Object {$_.DisplayName -like "$Name"}) | `

    Select DisplayName, PSChildName, DisplayVersion, UninstallString

    $app += (Get-ItemProperty HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* `
    -ErrorAction SilentlyContinue | `
    Where-Object {$_.DisplayName -like "$Name"}) | `

    Select DisplayName, PSChildName, DisplayVersion, UninstallString

    return $app
}

$GUID = Get-App -Name "$($appName)"

If ($GUID -ne $Null) {

    foreach ($app in $GUID) {

        $guid = $app.PSChildName

        Start-Process msiexec.exe -ArgumentList `
        "/x $guid /passive /norestart" -Wait
         
        $appGUID = Get-App -Name $app.DisplayName

        If (!$GUID) {
           Exit 0
        }

        else {
            Start-Process $($app.UninstallString) -ArgumentList `
            "/S" -Wait

            $GUID = Get-App -Name $app.DisplayName

            If (!$GUID) {

                Write-Output "App `"$($app.DisplayName)`" has been uninstalled successfully!"

                Exit 0

            } else {
            
                Write-Output "App `"$($app.DisplayName)`" FAILED to uninstall using msiexec and Uninstall string methods"

                Exit 1
            }
        }
    }
}

else

{
    Write-Output "No `"$appName`" app found!"
    Exit 0
}

```

It works only when I am logged in as administrator. I want to make it run regardless of user rights.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 27, 2023, 8:34am UTC](https://forums.powershell.org/t/script-to-uninstall-non-win32-program-for-all-profile-users/23221/2 "2023-11-27T08:34:08Z")

</div>

Giannis,  
Welcome to the forum. 👋🏼

> [@Giannis46](#):
>
> It works only when I am logged in as administrator. I want to make it run regardless of user rights.

If it is installed for “_All Users_” you need to run it elevated. There’s no way around it. 🤷🏼‍♂️

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:13pm UTC](https://forums.powershell.org/t/script-to-uninstall-non-win32-program-for-all-profile-users/23221/3 "2024-05-16T20:13:40Z")

</div>

Closed on May 16, 2024, 8:13pm UTC


