C#: Ask User for a Password which is then stored in a SecureString

前端 未结 2 1108
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-09 05:18

In the small application that I\'m currently developing for a customer I need to ask the user for his windows login username, password and domain and then use those with

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-09 05:48

    Try looking at the SecurePasswordTextBox custom control. Are you trying to do something similar to a "Run As" type command where you are trying to run the process as a different user than the one currently logged on? If not, you should be able to just call Process.Start and let it pick up the current users credentials.

    Also, take a look at the following resources as well:

    • CredUIPromptForCredentials
    • CredUIPromptForWindowsCredentials (Vista and Server 2008)
    • Microsoft Support article
    • LogonUser Function
    • LogonUserEx Function
    • CreateProcessAsUser
    • CreateProcessWithLogonW
    • CreateProcessWithTokenW

    The best option would probably be to use some interop p/inovke code to call CredUIPromptForCredentials to display the standard Windows dialog box and then use that information to either call Process.Start, or, more likely, call the CreateProcessAsUser function.

提交回复
热议问题