Tech Off Thread

5 posts

Elevate application on certain action in C#

Back to Forum: Tech Off
  • User profile image
    GurliGebis

    Is it possible for a problem to call a function, to get the UAC prompt up, so a certain function in my program i run as the Administrator.
    (Developing an application that downloads an MSI file over the network, and needs to run it as the Administrator, to get the application updated)

    And I do that?

  • User profile image
    T-Shooter

    No, you can't partially elevate an application. Only processes can be elevated.

    Thus, you need to ShellExecute another program - e.g. a console application created by you - using the "runas" verb to prompt the user for elevation.

  • User profile image
    Yggdrasil

    T-Shooter wrote:
    

    No, you can't partially elevate an application. Only processes can be elevated.

    Thus, you need to ShellExecute another program - e.g. a console application created by you - using the "runas" verb to prompt the user for elevation.



    Well, technically you can ask the user for a username and password and impersonate that account from your code, but this would require having the actual password, and requesting that from a user is mighty suspicious, and will probably trigger ANOTHER password check from UAC afterwards.

  • User profile image
    GurliGebis

    If I get the application to launch an MSI, wont vista ask about UAC then?

  • User profile image
    Sven Groot

    It should. If not right away, then at least when installation begins.

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.