[英]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.