gpt4 book ai didi

c# - 用户在这台机器上没有被授予请求的登录类型

转载 作者:太空狗 更新时间:2023-10-29 20:13:24 25 4
gpt4 key购买 nike

我创建了一个 ASP.Net 应用程序,它模拟用户以创建 AD 组,然后以用户身份启动 powershell 进程(与模拟分开)。

由于某种原因,组创建工作正常并在事件查看器中显示为成功,但是当它尝试运行 PowerShell 脚本时,出现以下错误:

The user has not been granted the requested logon type at this machine.

以下是我正在使用的失败代码:

SecureString securePassword = new SecureString();
foreach (char c in model.AdminPassword)
{
securePassword.AppendChar(c);
}
PSCredential psCredential = new PSCredential("CONTOSO\\" + User.Identity.Name, securePassword);

ProcessStartInfo info = new ProcessStartInfo("c:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe", "c:\\PowershellScripts\\EnableDL.ps1 -dlName '" + model.Name + "'");
info.UseShellExecute = false;
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
info.RedirectStandardInput = true;
info.CreateNoWindow = true;
info.Domain = "CONTOSO.COM";
info.UserName = User.Identity.Name;
info.Password = securePassword;

有什么办法可以绕过这个错误吗?我宁愿不在理想情况下摆弄服务器上的安全策略,而且这个应用程序需要被大约 30 多个用户使用。

最佳答案

我自己设法解决了这个问题。您需要转到“开始”->“管理工具”->“本地安全策略”。

导航到本地策略->用户权限分配->允许本地登录,并添加需要访问权限的帐户/组的用户名。

关于c# - 用户在这台机器上没有被授予请求的登录类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25477618/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com