未在此计算机上为用户授予所请求的登录类型

Sai*_*olf 8 c# asp.net powershell windows-server-2008

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

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

未在此计算机上为用户授予所请求的登录类型.

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

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;
Run Code Online (Sandbox Code Playgroud)

有没有办法绕过这个错误?我宁愿不理解服务器上的安全策略,这个应用程序需要大约30多个用户使用.

Sai*_*olf 9

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

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

  • https://blog.devoworx.net/2016/01/04/the-user-has-not-been-granted-the-requested-logon-type-at-this-computer/提到的详细步骤 (2认同)