4

We have a ClickOnce application that starts an external process with

p = new Process();
p.StartInfo.WorkingDirectory = Path.GetDirectoryName(exe);
p.StartInfo.FileName = Path.GetFileName(exe);
p.StartInfo.Arguments = arguments;
p.Start();

Usually, people ask whether it is possible to start the process as administration. But in my case it is the opposite:


I would like to make sure that this application is started as the user that is logged on. By default, that happens - for example when I test it.

But some users (Windows 8.1) report that the exe is started as administrator. For some weird reason, Windows automatically wants to start it as admin, even if it would not be necessary at all. If they right click on the exe and check the Properties, the box Run this program as an administrator is not checked!

When checking the exe file in the folder, it shows a UAC icon (example below):

enter image description here

Now I am wondering if it is programmatically possible to prevent that behavior and start the process in non-elevated state, maybe with a StartInfo property?

andreas
  • 7,844
  • 9
  • 51
  • 72
  • Is "wusa" your click once app or the app/process you spawn. The child process ought to start with the same level as the app which started it. – Ňɏssa Pøngjǣrdenlarp Mar 20 '16 at 00:03
  • No, it's just a random picture showing how the executable icon looks like, when Windows (for some weird reason) makes users start the program as admin. – andreas Mar 20 '16 at 22:37
  • Do you control that external exe you are starting from clickonce? – Evk Mar 25 '16 at 19:39
  • Hi @Evk, this is not my exe, it's an external program. The path to this program can be configured in my clickonce executable, and my application starts it (by using the given path) when the user clicks a button within my app. – andreas Mar 25 '16 at 22:13

3 Answers3

1

If application requires UAC, there are two reasons:

  1. There is a manifest (embedded into executable, or external one) which requires that.
  2. Windows decided, based on certain conditions, that application needs evelated permissions.

Since as you say in your question, the same executable does not require UAC on certain machines while does require on others - most likely there is no embedded manifest and that is Windows who decides this application needs evelation.

Here you can find somewhat dated, but I hope still relevant architecture of UAC. Under "Installer detection technology" you will see that even simple things like "The file name includes keywords such as "install," "setup," or "update." might cause windows to force UAC on that executable. First check if this somehow helps you to solve your problem (like maybe on some machines executable matches some of those criterias).

If that does not help, and because embedded manifest is unlikely - you can try to create external manifest for that exe (you can do this automatically before starting process) in which you request requestedExecutionLevel asInvoker. Put that manifest (it should be named .exe.manifest) near problem exe (not your clickonce application) and see if that helps. Hope you know how to create manifest file, if not - you can easily find that on Google or ask here. Note that if executable has embedded manifest already - it will have a priority (but that is unlikely).

Evk
  • 98,527
  • 8
  • 141
  • 191
0

Maybe this will help you? launch C# exe without prompting UAC on Windows 7

Add this to your manifest:

requestedExecutionLevel level="asInvoker" uiAccess="false"

"It could be that your third party DLL has to run in elevated mode, so your best option is to run as administrator. Bypassing the UAC prompt without running as administrator is a long complicated process"

Community
  • 1
  • 1
Yvo
  • 55
  • 6
  • 1
    It's not that easy to run a clickonce application as administrator, because it's not meant to be like that. There are workarounds, but I prefered to override the "start as" option of the other application because there is no reason that administrator rights are needed. – andreas Mar 19 '16 at 00:06
0

You're doing it right by not specifying any account information when creating a new Process instance: that'll rely on the default behavior of using the same user account running current process.

As for some users getting the "Run As Administrator" prompt: it may be that the security rules on the machine somehow identified the executable as not safe. Try to ask your customer to check whether in the properties page of the app they see an "Unblock" button. If so, let them click the "Unblock". That will eliminate that UAC prompt in the future.

Artak
  • 2,819
  • 20
  • 31