Windows Vista Forums » Discuss Microsoft ® Windows Vista ™ » Windows Vista Programming » C++, how to temporarily gain admin rights?

Windows Vista Programming A forum to discuss the challenges of programming under Windows Vista for experienced and aspiring programmers alike.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-23-2008
Junior Member
 
Join Date: Jun 2008
Posts: 3
Zadam is on a distinguished road
C++, how to temporarily gain admin rights?
Hey guys, wondering if anyone can help.

I know you can add some stuff to the manifest of an exe and it will throw up a UAC prompt as soon as the program is executed, but I was wondering is it possible to run an exe without admin rights (ie without the additions to the manifest file), but then if at some point they DO become required if theres a way to throw up the UAC prompt there and then, rather than when the exe is first run?

For example, the exe was run without UAC prompt, but now needs to save something to HKLM or to c:\program files, can the exe display the UAC prompt and then have admin rights to do these things?

Thanks in advance.

EDIT: For clarification, I am asking if there is some API etc which will do this.

Last edited by Zadam; 06-24-2008 at 12:25 AM..
Reply With Quote
  #2 (permalink)  
Old 06-23-2008
Celestra's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Riverside, CA (USA) Home of the Devil Winds
Posts: 430
Celestra has a spectacular aura about
Re: C++, how to temporarily gain admin rights?
Hi!! I hope this is what you're looking for: Bypass UAC - Vista Forums
__________________
Celestra

Last edited by Celestra; 06-23-2008 at 01:51 PM..
Reply With Quote
  #3 (permalink)  
Old 06-24-2008
Junior Member
 
Join Date: Jun 2008
Posts: 3
Zadam is on a distinguished road
Re: C++, how to temporarily gain admin rights?
Quote:
Originally Posted by Celestra View Post
Hi!! I hope this is what you're looking for: Bypass UAC - Vista Forums
Actually no, what I am after is a programmatic way to gain admin privilege in an executable, but bringing up the UAC prompt at runtime (at some point AFTER the exe is launched).
Reply With Quote
  #4 (permalink)  
Old 06-24-2008
Celestra's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Riverside, CA (USA) Home of the Devil Winds
Posts: 430
Celestra has a spectacular aura about
Re: C++, how to temporarily gain admin rights?
Quote:
Originally Posted by Zadam View Post
Actually no, what I am after is a programmatic way to gain admin privilege in an executable, but bringing up the UAC prompt at runtime (at some point AFTER the exe is launched).
Ah! I was hoping you didn't need it like a programmer......There's an article called " Least Privilege Teach Your Apps To Play Nicely
With Windows Vista User Account Control" (It mentions some of the things you are talking about- half way through the article). Editor's Note: Visual Studio at 10 There is also an intriguing software called "Resource Turner- How to add administrative privilege trust info" by heaven tools. I'm not sure if that will help. It work for XP and Vista....
__________________
Celestra
Reply With Quote
  #5 (permalink)  
Old 06-25-2008
Junior Member
 
Join Date: Jun 2008
Posts: 3
Zadam is on a distinguished road
Re: C++, how to temporarily gain admin rights?
Basically, what I'm trying to hint at, is there some new API in Vista that when called prompts the user with a UAC prompt, and if the user hits "yes" from then on the process which called that API is now running with admin privileges (in the same way it WOULD have been if admin rights were specified in the manifest).

eg:

void main()
{
// trying to create a file in c:\
// this will fail in Vista due to this process not having admin rights
HANDLE hFile = CreateFile("c:\\test.txt", ...);
if( hFile == INVALID )
{
// This is the API I am trying to figure out if exists, or if I could program my
// own version somehow using other API's
DisplaySecretVistaUACPrompt();

// Now try create file again since we now have admin rights (if the user said yes)
hFile = CreateFile("c:\\test.txt", ...);
}
...
}

I hope that's making what I need clear enough. I'm not really interested in articles describing how to change coding practices to make my process play nice, all I need is to be able to tell Vista that my process "I know I didn't ask for admin rights in my manifest, but I have changed my mind now and want them so can you please prompt the user for admin permission right now pretty please" and for Vista to prompt the user asking them if they will allow it.

Any further info and help appreciated.
Reply With Quote
  #6 (permalink)  
Old 08-10-2008
Celestra's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Riverside, CA (USA) Home of the Devil Winds
Posts: 430
Celestra has a spectacular aura about
Re: C++, how to temporarily gain admin rights?
Hi!! (Create Restricted Token API) Least Privilege: Teach Your Apps To Play Nicely With Windows Vista User Account Control
__________________
Celestra
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump





SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.