Mark McGinty
Mark McGinty

Reputation: 756

Cannot call ShellExecute "runas" from ClickOnce application

I have a ClickOnce app that needs to execute regasm, to register an assembly that it just updated.

If UAC is turned off, it works fine. If UAC is turned on, however, regsam's exit code is 100. If I run the same command in a cmd prompt, it fails with a message about needing admin privileges. If I use the run as admin option when I open the cmd prompt, it succeeds.

I tried changing asInvoker to highestAvailable in the manifest, which works locally, but ClickOnce refuses to publish it that way. I tried adding an imperative permissions demand for RegistryPermission, to no avail. I tried setting

ProcessStartInfo.verb = "runas" 

and .UseShellExecute = True

but still no love!

I've done a ton of reading about CAS, UAC and ClickOnce... I saw something about UAC being inconsistent with the ClickOnce dream (which strikes me as utter BS, but regardless) so I guess my question would be, is what I'm trying to do even possible? And if so, how?


The rest is just background info, that doesn't strictly pertain: The heinous part is, the project is done, except for this problem!

The purpose of the project is to automatically update a "shared" AddIn (IExtensibility2) for Outlook. Since we opted out of VSTO we can't use native ClickOnce support, so I created a ClickOnce app in which we embed the updated DLL as a resource. It's executed at startup, so when a new version of the ClickOnce app is available it automatically downloads; when it executes it compares the installed version to the version of the copy that's embedded, and prompts the user if its embedded version is newer. The hope was that we would be able to leverage ClickOnce rather than roll our own (which is what we did for the legace VB6 version.)

Upvotes: 2

Views: 995

Answers (1)

naiem
naiem

Reputation: 437

If you need more than sandboxed privileges, you better opt for full-trust apps. In .Net 4.0, all the CAS is deprecated. A fulltrust click once app in .Net 4.0 can do pretty much anything.

Upvotes: 1

Related Questions