Uninstall App Silently with System Privileges

uninstall app silently with system privileges

Here is how I did it:

ApplicationManager.java (changed part):

private PackageInstallObserver observer;
private PackageDeleteObserver observerdelete;
private PackageManager pm;
private Method method;
private Method uninstallmethod;

class PackageDeleteObserver extends IPackageDeleteObserver.Stub {

public void packageDeleted(String packageName, int returnCode) throws RemoteException {
/*if (onInstalledPackaged != null) {
onInstalledPackaged.packageInstalled(packageName, returnCode);
}*/
}
}
public ApplicationManager(Context context) throws SecurityException, NoSuchMethodException {

observer = new PackageInstallObserver();
observerdelete = new PackageDeleteObserver();
pm = context.getPackageManager();

Class<?>[] types = new Class[] {Uri.class, IPackageInstallObserver.class, int.class, String.class};
Class<?>[] uninstalltypes = new Class[] {String.class, IPackageDeleteObserver.class, int.class};

method = pm.getClass().getMethod("installPackage", types);
uninstallmethod = pm.getClass().getMethod("deletePackage", uninstalltypes);
}
public void uninstallPackage(String packagename) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
uninstallmethod.invoke(pm, new Object[] {packagename, observerdelete, 0});
}

PackageDeleteObserver.java (in android.content.pm):

package android.content.pm;

public interface IPackageDeleteObserver extends android.os.IInterface {

public abstract static class Stub extends android.os.Binder implements android.content.pm.IPackageDeleteObserver {
public Stub() {
throw new RuntimeException("Stub!");
}

public static android.content.pm.IPackageDeleteObserver asInterface(android.os.IBinder obj) {
throw new RuntimeException("Stub!");
}

public android.os.IBinder asBinder() {
throw new RuntimeException("Stub!");
}

public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags)
throws android.os.RemoteException {
throw new RuntimeException("Stub!");
}
}

public abstract void packageDeleted(java.lang.String packageName, int returnCode)
throws android.os.RemoteException;
}

Also dont forget to add permission to manifest:

<uses-permission android:name="android.permission.DELETE_PACKAGES"/>

Working sample project (apk need to be placed in "/system/app" path on device):
http://www.mediafire.com/file/no4buw54ed6vuzo/DeleteInBackgroundSample.zip

silent uninstall msi package command WITHOUT administrative rights

That error from the log file indicates that a custom action is crashing. You'll want to investigate the root cause of that issue. My guess is that the custom action requires elevation (admin privileges) to work correctly but is not marked deferred (i.e. runs during the part when the MSI is elevated).

If you launch the uninstall of the MSI from Add/Remove Programs (Programs and Features) then you should not be prompted for elevated credentials. Thus the root issue probably is this custom action.

Msiexec uninstall using elevated privileges and admin user credentials from c# or cmd

Not sure why I didn't try this solution before:

Use msiexec.exe option /passive together with the /quiet parameter.
This displays the uninstall/install progress bar during uninstall and the install process and also prompts you UAC if you have it enabled.

So in essence the solution for me is as follows:

1. Same as my previous answer, I needed to raise the UAC level from None to Notify me only when apps try to make changes to my computer (do not dim my desktop).

2. change the following c# code to contain the /passive parameter

string uninstallCommand = String.Format("/quiet /passive /uninstall {0}", productCode);

You still have to remember to Run your application as administrator to get the logging to work. What this did however is prompt UAC permission which elevates the installer permission to admin level and proceed to uninstall the software successfully.

Installshield Silent Uninstall not working at Command Line

You need to create first an ISS response file to silently remove your application,

  1. Create response file :
    C:\App\Setup.exe /r /f1c:\app\uninstall1.iss
    you will be asked to uninstall, .... and perhaps reply the others windows.
    Then your application would be uninstalled and you get a new response file c:\app\uninstall1.iss

  2. Next, if you want to remove silently this application on another computer :
    launch : C:\App\Setup.exe" /s /f1c:\app\uninstall1.iss

For more information see:

http://www.itninja.com/blog/view/installshield-setup-silent-installation-switches

Best Regards,
Stéphane

Uninstalling an MSI file from the command line without using msiexec

Short answer: you can't. Use MSIEXEC /x

Long answer: When you run the MSI file directly at the command line, all that's happening is that it runs MSIEXEC for you. This association is stored in the registry. You can see a list of associations by (in Windows Explorer) going to Tools / Folder Options / File Types.

For example, you can run a .DOC file from the command line, and WordPad or WinWord will open it for you.

If you look in the registry under HKEY_CLASSES_ROOT\.msi, you'll see that .MSI files are associated with the ProgID "Msi.Package". If you look in HKEY_CLASSES_ROOT\Msi.Package\shell\Open\command, you'll see the command line that Windows actually uses when you "run" a .MSI file.

How to silently and automatically deploy and install Github CLI on Windows?

  • As you state, quiet (unattended, no-UI) installation requires running from an elevated session.

  • In the context of PowerShell remoting via Invoke-Command -ComputerName, a remote session automatically and invariably runs with elevation - assuming that the target user is a member of the BUILTIN\Administrators group on the remote machine.

Therefore, try something like the following (assumes that the current user is an administrator on the target machines):

Invoke-Command -Computer $computers -ScriptBlock {
# Use of cmd /c ensures *synchronous* execution
# (and also interprets %WINDIR% as intended).
cmd /c 'MsiExec.exe /i gh_2.10.1_windows_amd64.msi /qn /L*v "%WINDIR%\Temp\GitHubCLI-Install.log'
if ($LASTEXITCODE -ne 0) { throw "Installation failed with exit code $LASTEXITCODE." }
}

To run the installer on the local machine - from an elevated session - simply run the command from the script block above directly, i.e.:

# Must run WITH ELEVATION.
# Check $LASTEXITCODE afterwards.
cmd /c 'MsiExec.exe /i gh_2.10.1_windows_amd64.msi /qn /L*v "%WINDIR%\Temp\GitHubCLI-Install.log'


Related Topics



Leave a reply



Submit