Windows Vista C++, how to temporarily gain admin rights?

Discussion in 'Programming and Scripting' started by Zadam, Jun 23, 2008.

  1. Zadam

    Zadam New Member

    Joined:
    Jun 23, 2008
    Messages:
    6
    Likes Received:
    0
    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.
     
  2. Celestra

    Celestra Former Moderator

    Joined:
    Jan 15, 2008
    Messages:
    2,468
    Likes Received:
    14
  3. Zadam

    Zadam New Member

    Joined:
    Jun 23, 2008
    Messages:
    6
    Likes Received:
    0
    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).
     
  4. Celestra

    Celestra Former Moderator

    Joined:
    Jan 15, 2008
    Messages:
    2,468
    Likes Received:
    14
    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....
     
  5. Zadam

    Zadam New Member

    Joined:
    Jun 23, 2008
    Messages:
    6
    Likes Received:
    0
    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.
     
  6. Celestra

    Celestra Former Moderator

    Joined:
    Jan 15, 2008
    Messages:
    2,468
    Likes Received:
    14

Share This Page

Loading...