简体   繁体   English

UNC LogonUser:未知用户或密码错误

[英]UNC LogonUser: Unknown user or bad password

I have a weird scenario here. 我这里有一个奇怪的情况。 My app connects to a fileserver to list the files from a directory using UNC. 我的应用程序连接到文件服务器,以使用UNC列出目录中的文件。 It has been working for the past couple of years without any problem. 在过去的两年中,它一直没有任何问题。 Recently, my network admin rebooted the server as a result of which I started getting LogonUser : Unknown user or bad password error. 最近,我的网络管理员重新启动了服务器,结果我开始获取LogonUser:未知用户或密码错误错误。 As per the network admin, everything is set up correctly for the domain user account. 按照网络管理员的要求,域用户帐户的所有设置均正确设置。 The username and password are all correct. 用户名和密码均正确。 Is there anything I need to change in the code below? 我需要在下面的代码中进行任何更改吗?

const int LOGON32_LOGON_INTERACTIVE = 2;
const int LOGON32_LOGON_NETWORK = 3;
const int LOGON32_LOGON_BATCH = 4;
const int LOGON32_LOGON_SERVICE = 5;
const int LOGON32_LOGON_UNLOCK = 7;
const int LOGON32_LOGON_NETWORK_CLEARTEXT = 8;
const int LOGON32_LOGON_NEW_CREDENTIALS = 9;
const int LOGON32_PROVIDER_DEFAULT = 0;

[DllImport("advapi32.dll", SetLastError = true)]
public static extern int LogonUser(
    string lpszUsername,
    string lpszDomain,
    string lpszPassword,
    int dwLogonType,
    int dwLogonProvider,
    out IntPtr phToken
    );
[DllImport("advapi32.dll", SetLastError = true)]
public static extern int ImpersonateLoggedOnUser(
    IntPtr hToken
);

[DllImport("advapi32.dll", SetLastError = true)]
static extern int RevertToSelf();

[DllImport("kernel32.dll", SetLastError = true)]
static extern int CloseHandle(IntPtr hObject);
int TResult = LogonUser(ConfigurationManager.AppSettings["ServerUserName"].ToString(), @"\\server\folder", ConfigurationManager.AppSettings["ServerPassword"].ToString(), LOGON32_LOGON_NEW_CREDENTIALS, LOGON32_PROVIDER_DEFAULT, out lnToken);

Please advise on what else I should be checking with my network admin. 请告知我应与网络管理员联系的其他事项。 Thanks in advance. 提前致谢。

I don't see anything inherently wrong with the code that you are executing. 我看不到您正在执行的代码有天生的错误。 So, I'm not certain why this would suddenly STOP working. 因此,我不确定为什么这会突然停止工作。 However, if you are open to a little re-factoring there appear to be others that have run into similar issues. 但是,如果您愿意进行一些重构,那么似乎其他人也遇到了类似的问题。 One of the below answers should give you the insight you need. 以下答案之一应为您提供所需的见解。

How to Impersonate a user for a file copy over the network when dns or netbios is not available 当dns或netbios不可用时,如何通过网络模拟用户以获取文件副本

Accessing Password Protected Network Drives in Windows in C#? 使用C#在Windows中访问受密码保护的网络驱动器?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 登录失败:用户名未知或密码错误 - Logon failure: unknown user name or bad password StreamWriter引发IOException登录失败:用户名未知或密码错误 - StreamWriter throws IOException Logon failure: unknown user name or bad password 登录失败:用户名未知或密码错误? 但是我使用正确的用户名和密码 - Logon failure: unknown user name or bad password? But I am using the right username and password 登录失败:用户名未知或密码错误。访问其他服务器时出错 - Logon failure: unknown user name or bad password.error while accessing other server 登录失败:在远程计算机中创建文件夹时,用户名未知或密码错误 - Logon failure: unknown user name or bad password while creating folder in remote machine 登录失败:用户名未知或密码错误。 使用C#的FTP - Logon failure: unknown user name or bad password. FTP with C# AD身份验证未知的用户名或密码错误 - AD Authentication Unknown username or bad password LogonUser调用-用户是否需要该计算机的登录权限? - LogonUser call - does the user need login rights to that machine? 如何正确使用 LogonUser 从工作组客户端模拟域用户 - How to use LogonUser properly to impersonate domain user from workgroup client 模仿用户时如何将SecureZeroMemory与LogonUser一起使用? - How do I use SecureZeroMemory with LogonUser when impersonating a user?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM