C# - 以空白密码的用户身份运行新进程
我有一个从主应用程序生成的子进程,需要在 Windows 7 计算机上作为另一个本地用户运行。我不想在该用户帐户上设置密码,但似乎通过模拟创建新进程不允许使用空白密码或任何类型的空值。有人知道这是否可能吗?
下面是我传递空白字符的尝试:
ProcessStartInfo info = new ProcessStartInfo(@"C:\PathToExecutable");
System.Security.SecureString psswd = new System.Security.SecureString();
psswd.AppendChar('\0');
psswd.MakeReadOnly();
info.UseShellExecute = false;
info.UserName = "NewProcessName";
info.Password = psswd;
info.Domain = "LocalMachine";
Process newProc = new Process();
newProc.StartInfo = info;
newProc.Start();
编辑: 我收到错误消息
登录失败:用户帐户限制。可能的原因是不允许使用空白密码、登录时间限制或已强制执行策略限制
I have a child process I spawn from my main application that needs to be run as another local user on a Windows 7 machine. I would prefer to not set a password on that user account, but it seems that creating a new process with impersonation does not allow for blank passwords or any type of null values. Anyone know if this is possible?
below was my attempt with passing a blank char:
ProcessStartInfo info = new ProcessStartInfo(@"C:\PathToExecutable");
System.Security.SecureString psswd = new System.Security.SecureString();
psswd.AppendChar('\0');
psswd.MakeReadOnly();
info.UseShellExecute = false;
info.UserName = "NewProcessName";
info.Password = psswd;
info.Domain = "LocalMachine";
Process newProc = new Process();
newProc.StartInfo = info;
newProc.Start();
edit:
The error message I recieve
Logon failure: user account restriction. Possible reasons are blank passwords not allowed, logon hour restrictions, or a policy restriction has been enforced
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为此,您必须禁用安全策略
这里还有其他解决方案:
https://sites.google.com/site/sqlestream/windows-issue/10-cannot-access-the-shared-folder-due-to-blank-password-not-allowed
和那么您将能够执行一个进程而无需声明用户密码
For to do this you have to disable a security policy
there is other solution here:
https://sites.google.com/site/sqlestream/windows-issue/10-cannot-access-the-shared-folder-due-to-blank-password-not-allowed
and then you will be able to execute a process without declaring an user password
你用什么来冒充?
LogonUser()
应允许空白密码。我认为调用
psswd.AppendChar('\0')
不是指定空白密码的正确方法。尝试从代码中删除SecureString
以查看是否至少可以使模拟工作。然后重新添加 SecureString 以查看问题是否出在此处。* 编辑*
试试这个:
将
info.Password
设置为您的新 SecureString...不确定您是否必须在unsafe
是否有上下文。What are you using to impersonate?
LogonUser()
should allow a blank password.I don't think calling
psswd.AppendChar('\0')
is the right way to specify a blank password. Try removing theSecureString
from your code to see if you can at least make the impersonation work. Then add the SecureString back in to see if your problem lies there.* Edit *
Try this:
set
info.Password
to your new SecureString... not sure if you'll have to do that within theunsafe
context or not.作为这个问题指出,在
StartInfo
中将LoadUserProfile
设置为true。尝试一下,可能会有所帮助。As this question points out, set
LoadUserProfile
to true inStartInfo
. Try that out, it might help.这显然是一个已知问题,
LogonUser()
因密码为空而失败。我在我的用例中为所需的用户帐户设置了通用密码。This is apparently a known issue that
LogonUser()
fails with a blank password. I set a generic password for required user accounts in my use case.