none
Thread Elevation? RRS feed

  • Question

  • Hello.

    I don't know if this is the correct forum to post but here is my problem:

    Directory.CreateDirectory("C:\\Windows\\dir"); 

    The following code runs as a user, which belongs to administrators and it causes Exception:

    System.UnauthorizedAccessException
    Message="Access to the path 'C:\\Windows\\dir' is denied."

    Obviously the application needs to start elevated in order to be able to create that folder (indeed it does).
    Is there a way to get elevated permissions programmatically at runtime without having to change the manifest of the application or asking for elevation at the beginning? Please note that the whole operation is done remotely (there is no UI and such).
    If yes can I elevate only a specific thread?

    Thank you in advance.
    • Edited by bookysmell2004 Sunday, June 15, 2008 5:31 PM added details
    Sunday, June 15, 2008 5:28 PM

All replies

  • Hi

    You can impersonate as a Admin User and run that particular part of code.

    Thanks n Regards
    Anu Viswan.

    Anu Viswan : www.AnuViswan.blogspot.com
    Monday, June 16, 2008 10:07 AM
  • Hi. Thanks for the reply.

    The user who is running the above program is an admin user.
    The only that's missing is to bypass the UAC without disabling it.
    Monday, June 16, 2008 11:30 AM