1

When I'm running Visual Studio as admin, and I use it to run my C# application, it automatically runs the application as admin.
This causes problems when it tries to use interop, because instead of connecting to running processes, it launches new ones as admin.
It's an easy mistake to make, and debugging doesn't help catch it.

I'd like to make sure the application runs at a lower UAC level, or stop it from running at all if the permissions are wrong.

I'm aware of <requestedExecutionLevel> in the application manifest. The problem is that the only levels it seems to provide are asInvoker, requireAdministrator, and highestAvailable. As far as I can tell, these only raise the level, not lower it.

TheGreatB3
  • 65
  • 2
  • 7
  • You problem is not admin let me tell you that. It's the way you are dealing with your interop that has something wrong – Franck Jul 24 '19 at 18:25
  • 1
    I'm curious as to why you are doing the development as admin? – lurker Jul 24 '19 at 18:26
  • @lurker Visual Studio has to be in admin to use "Register for COM Interop." That's for a different project, but if I forget to switch back things start going wrong, and it's hard to figure out why. – TheGreatB3 Jul 24 '19 at 18:39
  • @TheGreatB3 No it does not necessary. This is only because you run from F5. The exe ran from VS use same credential as VS was started with. This can also be limited with Domain policy where even with run as admin you wont be able to register due to limitation with new registry key. – Franck Jul 24 '19 at 18:44
  • @Franck I'm not sure we're on the same page. One VS solution makes an assembly that is registered for COM interop, and thus has to be built with VS as admin. The other solution makes an EXE and connects with other programs that are already running (not as admin). The problem happens when I run the EXE solution from VS (F5) if VS is still admin, because it runs the EXE as admin. – TheGreatB3 Jul 24 '19 at 19:06
  • How is a COM interop a running process ? A COM Interop is just a DLL front it's not actively running. – Franck Jul 24 '19 at 19:19
  • would [this](https://stackoverflow.com/a/41110726/937093) help solve your issue? – Steffen Winkler Jul 24 '19 at 19:37
  • @Franck The COM DLL doesn't run. The EXE runs, and it's supposed to connect to a running Excel process. But if the EXE is run from VS when VS is still admin, then the EXE is admin, and instead of connecting to the running Excel process, it tries to start Excel as admin, which I don't want. – TheGreatB3 Jul 24 '19 at 19:37
  • @SteffenWinkler I think it would, thank you. – TheGreatB3 Jul 24 '19 at 19:41

0 Answers0