C# - 以空白密码的用户身份运行新进程

发布于 2024-09-16 07:03:43 字数 630 浏览 12 评论 0原文

我有一个从主应用程序生成的子进程,需要在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

哆啦不做梦 2024-09-23 07:03:43

为此,您必须禁用安全策略

  1. 转至控制面板 → 管理工具 → 本地安全策略。
  2. 浏览安全设置→本地策略→安全选项...查找“帐户:限制本地帐户仅使用空白密码进行控制台登录”。
  3. 选择禁用并应用

这里还有其他解决方案:
https://sites.google.com/site/sqlestream/windows-issue/10-cannot-access-the-shared-folder-due-to-blank-password-not-allowed

ProcessStartInfo procStartInfo = new ProcessStartInfo("File Name", "Argument(Optional)")
{
      UserName = "UserName",
      RedirectStandardError = true,
      RedirectStandardOutput = true,
      UseShellExecute = false,
      CreateNoWindow = true
};
using (Process proc = new Process())
{
       proc.StartInfo = procStartInfo;
       proc.Start();
}

和那么您将能够执行一个进程而无需声明用户密码

For to do this you have to disable a security policy

  1. Go to Control Panel → Administrative Tools → Local Security Policy.
  2. Browse the Security Settings → Local Policies → Security Options... Look for "Accounts: Limit local account use of blank password to console logon only".
  3. Select Disabled and APPLY

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

ProcessStartInfo procStartInfo = new ProcessStartInfo("File Name", "Argument(Optional)")
{
      UserName = "UserName",
      RedirectStandardError = true,
      RedirectStandardOutput = true,
      UseShellExecute = false,
      CreateNoWindow = true
};
using (Process proc = new Process())
{
       proc.StartInfo = procStartInfo;
       proc.Start();
}

and then you will be able to execute a process without declaring an user password

童话 2024-09-23 07:03:43

你用什么来冒充? LogonUser() 应允许空白密码。

我认为调用 psswd.AppendChar('\0') 不是指定空白密码的正确方法。尝试从代码中删除 SecureString 以查看是否至少可以使模拟工作。然后重新添加 SecureString 以查看问题是否出在此处。

* 编辑*

试试这个:

unsafe {
    char* ary = stackalloc char[0];
    SecureString str = new SecureString(ary, 0);
}

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 the SecureString 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:

unsafe {
    char* ary = stackalloc char[0];
    SecureString str = new SecureString(ary, 0);
}

set info.Password to your new SecureString... not sure if you'll have to do that within the unsafe context or not.

深海少女心 2024-09-23 07:03:43

作为这个问题指出,在StartInfo中将LoadUserProfile设置为true。尝试一下,可能会有所帮助。

As this question points out, set LoadUserProfile to true in StartInfo. Try that out, it might help.

后来的我们 2024-09-23 07:03:43

这显然是一个已知问题,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文