Starting another process with elevation using different user credentials

前端 未结 5 888
旧巷少年郎
旧巷少年郎 2021-02-04 02:00

I\'m trying to start an elevated process from with a non-elevated process, but I also need to supply the username and password for a user with administrative credentials. I\'ve

5条回答
  •  天涯浪人
    2021-02-04 02:25

    i was surprised there's no way to do this, until i found an on blog entry by Chris Jackson:

    Why Can’t I Elevate My Application to Run As Administrator While Using CreateProcessWithLogonW?

    You need a bootstrapper. Some process which will let you do the transition to the alternate user, which could be responsible for running the requireAdministrator application. So, you could design something like this:

    enter image description here

    Why don’t we just create the ShellExecuteWithLogonW API? I’ll never say never, and we might at some point. But today, the use cases for this APIs have been use cases where there has been an alternate design which is superior.

    The most common request is for people writing home-grown software deployment software, where they’d like to encode credentials right into the app and elevate their own process. The real problem here is not the lack of the API, it’s that you have admin credentials encoded in your app for the world to read.

    So the solution requires ShellExecute, it's the only one that knows how to trigger a Consent dialog.

    It brings up a good point: What are you doing with a person's password already?

    Bonus Chatter

    There's no UAC on Server Core because there's no windows to show a consent prompt.

提交回复
热议问题