gpt4 book ai didi

c# - LogonUser 失败,错误代码为 : 1326

转载 作者:行者123 更新时间:2023-11-30 12:47:18 33 4
gpt4 key购买 nike

谁能帮我解决这个问题?我试图使用所需的凭据登录到 portal.microsoftonline.com,但它给我带来了错误。是我的网址有误还是什么?因为我试图模仿并赋予用户角色。谢谢,顺便说一句,我是新来的,请原谅我发布问题的方式。请查看错误所在的评论。

   class SecurityHelpers
{
private SecurityHelpers() { }

[DllImport("advapi32.dll", SetLastError = true)]
private static extern bool LogonUser(string lpszUsername,
string lpszDomain, string lpszPassword,
int dwLogonType, int dwLogonProvider, ref IntPtr phToken);

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private extern static bool CloseHandle(IntPtr handle);

public static WindowsIdentity CreateIdentity(
string userName, string domain, string password)
{
IntPtr tokenHandle = new IntPtr(0);

const int LOGON32_PROVIDER_DEFAULT = 0;
const int LOGON32_LOGON_NETWORK_CLEARTEXT = 3;

tokenHandle = IntPtr.Zero;
bool returnValue = LogonUser(userName, domain, password,
LOGON32_LOGON_NETWORK_CLEARTEXT,
LOGON32_PROVIDER_DEFAULT,
ref tokenHandle);

if (false == returnValue)
{
int ret = Marshal.GetLastWin32Error();
// THIS WHERE THE ERROR IS - "LogonUser failed with error code: 1326"
throw new Exception("LogonUser failed with error code: " + ret);
}

WindowsIdentity id = new WindowsIdentity(tokenHandle);
CloseHandle(tokenHandle);
return id;
}
}

最佳答案

xp_cmdshell 可能是通过代理帐户执行的。检查代理帐户是否具有正确的凭据。

在对象资源管理器中转到:

Security > Credentials > ##xp_cmdshell_proxy_account##

另外,检查用户是否有sys.xp_cmdshell的执行权限

在对象资源管理器中转到:

Databases > System Databases > master > Security > Users > [user] > Securables

授予权限的SQL:

use [master]
grant execute on xp_cmdshell to [domain\user];

关于c# - LogonUser 失败,错误代码为 : 1326,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17332977/

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