Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# security WinForm
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
v2
Comments
Indivara at 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 at 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
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
v3
Comments
Indivara at 1-Feb-11 8:56am
   
That restarts the _entire_ app with admin privileges.
Prerak Patel at 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 at 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
0 OriginalGriff 520
1 Maciej Los 290
2 Richard MacCutchan 265
3 BillWoodruff 265
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,764
1 Sergey Alexandrovich Kryukov 7,437
2 DamithSL 5,639
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411028.1 | Last Updated 1 Feb 2011
Copyright © CodeProject, 1999-2014
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