Uninstall an application without user input

All we need is an easy explanation of the problem, so here it is.

Below is a PowerShell script I am running on Windows 10 to uninstall HP Support Assistant but it keeps prompting the end-users for input and such, and this is what I need to prevent.

Question: How can I uninstall this application silently or without the need for user interaction?

Note: I am able to access these machines remotely with admin permissions.


PowerShell Script

$laptops = Get-Content "c:\scripts\laptops.txt";

$laptops | %{
    $app = Get-WmiObject Win32_Product -ComputerName $_ | ?{$_.name -eq "HP Support Assistant"};
    $app.Uninstall();
    };

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

First of all, you have to check for the silent uninstall command.

For this purpose I usually use this tool: https://www.nirsoft.net/utils/uninstall_view.html

UninstallView is a tool for Windows that collects information about all programs installed on your system and displays the details of the installed programs in one table. You can use it to get installed programs information for your local system, for remote computer on your network, and for external hard-drive plugged to your computer. It also allows you to easily uninstall a software on your local computer and remote computer (Including quiet uninstall if the installer supports it).

The tool displays the silent uninstall command.

If you find the command, try it out manually. Sometimes, even a command is provided, silent uninstall doesn’t work as expected.

Second, my recommendation is not to use WMI for uninstall, cause it is slow in determine the installed programs.
Instead check for the registry key, which is also displayed by the tool.

To be more generic, read in these keys

HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

search for DisplayName with a where statement and execute the command in the quietuninstall key.

Method 2

Uninstall an application silently

To uninstall an application, you can run the uninstall process as a startup script so it does not require any end-user input or interaction to complete the uninstall operation.

Since you are using PowerShell and already have logic you confirm uninstalls the application you need, the example provided will build off of that to keep it simple and basic.

Furthermore, beneath that I will provide an additional but different (and more efficient) way to uninstall the package using PowerShell since you are using Windows 10.

  1. PowerShell Script (existing logic)

    Note: Save this to C:\Scripts\Test.ps1 or on the local machine or perhaps a UNC path that you’ve granted Domain Computers and/or
    Authenticated Users to the folder and the share.

    $app = Get-WmiObject -Class Win32_Product | ?{$_.name -eq "HP Support Assistant"};
    $app.Uninstall();
    
  2. PowerShell Script (more effecient logic)

    Note: This uses Get-Package with the package name and pipes that over to
    Uninstall-Package
    to uninstall the application from Windows.

    $pName = "HP Support Assistant";
    Get-Package $pName | Uninstall-Package;
    

Run as a startup script using Group Policy settings

Note: Use gpedit.msc on the local machine to run the script as a Startup Script or if you are able use Group Policies from Active
Directory if applicable in a domain environment.

  1. Go to gpedit.msc
  2. Navigate Computer Configurations | Windows Settings | Scripts (Startup/Shutdown)
  3. Click on Startup | PowerShell Scripts tab | Add option
  4. Point the Script Name field to the full path of the startup script location
  5. Press OK and/or Apply out of all existing screens to save the settings

  6. Lastly, you will just want to restart the computer to ensure the startup script runs and uninstalls the application without any need for user interaction or input.

enter image description here


Other Potential Solution

According to an answer on the HP Silent Uninstall HP Support Assistant post, you can also uninstall the HP Support Assistant application while logged on and not as a login script silently using:

"C:\Program Files (x86)\Hewlett-Packard\HP Support Framework\UninstallHPSA.exe" /s /v /qn


Supporting Resources

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply