问题描述
在这我目前正在开发一个客户,我需要询问用户他的Windows登录用户名,密码和域名,然后使用这些与小应用程序的 System.Diagnostics.Process.Start 启动应用程序。
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 System.Diagnostics.Process.Start to start an application.
我有UseSystemPasswordChar一个文本框来掩盖输入的密码。
I have a textbox with UseSystemPasswordChar to mask the entered password.
我需要一个为System.Security.SecureString 喂密码的 System.Diagnostics.Process.Start 。
I need a System.Security.SecureString to feed the password to System.Diagnostics.Process.Start.
如何转换输入的文本,以确保字符串,而接连不这样做的一个字符?另外:有没有更好的窗口控制,要求返回输入的文本作为SecureString的用户输入密码
How do I convert the entered text to secure string while not doing it one character after another? Alternatively: Is there a better window control to ask the user for a password that returns the entered text as SecureString?
推荐答案
尝试寻找在自定义控件。你试图做类似你在哪里试图运行过程作为一个不同的用户一个比当前登录的一个运行方式命令型的东西?如果没有,你应该能够只需要调用的Process.Start,让它拿起当前用户的凭据。
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:
- (Vista和Server 2008中)
- 的
- 的
- 的
- CredUIPromptForCredentials
- CredUIPromptForWindowsCredentials (Vista and Server 2008)
- Microsoft Support article
- LogonUser Function
- LogonUserEx Function
- CreateProcessAsUser
- CreateProcessWithLogonW
- CreateProcessWithTokenW
最好的办法可能是使用一些互操作的p / inovke代码来调用CredUIPromptForCredentials显示标准的Windows对话框中,然后使用该信息或者调用的Process.Start,或者更可能的是,调用CreateProcessAsUser函数。
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.
这篇关于C#:询问用户的,然后存储在SecureString的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!