Click here to Skip to main content
16,019,876 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
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
Updated 1-Feb-11 3:37am
v2
Comments
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.
fjdiewornncalwe 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]
#realJSOP 1-Feb-11 10:26am    
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

 
Share this answer
 
v3
Comments
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.

4
down vote
accepted
"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 http://stackoverflow.com/questions/573086/how-to-elevate-privileges-only-when-required

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...
#realJSOP 1-Feb-11 8:59am    
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900