Uninstalling with msiexec gets UAC error, even though I have admin rights set

StackOverflow https://stackoverflow.com/questions/4147286

  •  30-09-2019
  •  | 
  •  

Pergunta

I'm trying to build an updater using msiexec to uninstall a program, then install the newer version.
Here's my code:

command = "/x{[uninstall string here]}";
command += "/qn+ /Le c:\\test\\msilog.txt";
ProcessStartInfo psi = new ProcessStartInfo("msiexec");
psi.Arguments = command;
//psi.UseShellExecute = true;
//psi.Verb = "runas";
Process.Start(psi);

I have

<requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />

set in my manifest, and that is set as the Application's manifest. When I run this I get the popup box that says "AppSetup failed" and the log file says

Error 1730. You must be an Administrator to remove this application. To remove this application, you can log on as an Administrator, or contact your technical support group for assistance.

IF, however, I run cmd as administrator, and type in

msiexec /x{[uninstall string here]} /qn+ /Le c:\\test\\msilog.txt

It works fine and dandy.
What am I missing here?

(I've also tried uncommenting those two lines above, as that was one way I found to run as Administrator, but it then pops up the UAC dialog before trying to execute, even though /qn is set.)

Foi útil?

Solução

To elevate a process you need to have the user approve it. If every process could elevate itself without user interaction it would somewhat defeat the purpose of elevation.

I don't know your full scenario, but if you can managed to execute your updater from the Local Service account then this should work without user interaction. A few ways that come to mind are by installing a windows service, Run/RunOnce key of local service account, or using psexec with -s. Of course to accomplish this, you need to have the right permissions yourself on the client machine.

Good luck.

*One more thing: If you haven't looked into this yet, you can use Windows Installer to update your installation and do not need to write your own "updater." There are 3 different types of updates (small update, minor upgrade, and major upgrade): http://msdn.microsoft.com/en-us/library/aa370579(VS.85).aspx

A major upgrade uninstalls the previous version and installs the newer version which is most similar to what you've described, though in most cases small updates and minor upgrades are more fitting.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top