Click here to Skip to main content
11,928,352 members (58,648 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# security
I have an app that can mostly run as the current non-admin user, but some features of the app (user-activated by way of a button click) need to have admin privileges to work. I want the UAC to pop up when the user tries to use these privileged features, but I don't want to have to run the app as admin. Is that possible without moving the privileged features into their own executable?

I've been googling for the last hour or so, and I can't find anything that doesn't require the entire app to be run as admin.

EDIT =============

As it stands right now, my solution was to create a separate console application to contain the privileged code. It's not the way I wanted to do it, and at best it's merely a work-around.

I guess I can understand the possibility of exploiting some esoteric attack vector if running parts of a program with elevated privileges was allowed, but this is damn inconvenient. I thought they called this stuff "managed" code.
Posted 1-Feb-11 3:47am
Edited 1-Feb-11 4:37am
Indivara 1-Feb-11 8:58am
I've searched for this once and given up. Hope I'm wrong, but I think it is impossible.
Marcus Kramer 1-Feb-11 10:09am
An excellent question. I'll have to look into this a bit tonight, I think. It seems to me that in Windows 7 it should be possible since auto-updater applications seem to do what you are asking.
[Edit]Like you say, I wonder if the way to do it is to spawn a separate process when to activate these features and that this would be the workaround.[/Edit]
But it has to work on XP and Vista as well. I can't really rely on something that's just in Windows 7. However, if you find something, by all means let me know. I have the workaround described above in place, and it works well (despite the fact that I had to create a completely separate app to do it - grumble, grumble).

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Indivara 1-Feb-11 8:56am
That restarts the _entire_ app with admin privileges.
Prerak Patel 1-Feb-11 9:01am
Yes, but that's how it works.

down vote
"I don't believe that it is possible to elevate the currently running process. It is built into Windows Vista that administrator privileges are given to a process upon startup, as I understand." from

Still I got some links, it that can help. Updating the answer.
Indivara 1-Feb-11 19:07pm
Yeah, thanks for the link. I wasn't criticizing you (no down-votes from me), it just seems strange that nowhere in the documentation does it say so clearly. The ability to elevate one assembly, while the entire app is still running, would have been nice. Just wishful thinking...
Like Indivara said, it restarts the app as admin - I don't want to do that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.1 | Last Updated 1 Feb 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100