【发布时间】:2024-05-03 05:45:02
【问题描述】:
我们有一个连接到云驱动器的软件。该软件已经在 2 台不同的服务器上运行了 2 年,没有出现任何问题。在两台服务器上都运行完全相同版本的软件,并且都使用相同的用户凭据连接到同一驱动器。两台服务器都使用 Windows 10 企业版。
现在他们不得不将网络驱动器的名称从 "\cloudserver-name\CentralEurope\path\to\directory" 到 "\域名\EU_Central\path\to\directory"
我们在两台服务器的软件配置中对此进行了更改。现在一个可以连接,而另一个不能再连接。它抛出一个 1232 错误(网络位置不能 到达。有关网络故障排除的信息,请参阅 Windows 帮助。
如果我们尝试通过 Windows 资源管理器进行连接,它在两台服务器上都可以正常运行,但一台服务器仍然无法连接到该软件。
至于代码,我们正在运行它以连接到 UNC-Path:
internal struct USE_INFO_2
{
internal LPWSTR ui2_local;
internal LPWSTR ui2_remote;
internal LPWSTR ui2_password;
internal DWORD ui2_status;
internal DWORD ui2_asg_type;
internal DWORD ui2_refcount;
internal DWORD ui2_usecount;
internal LPWSTR ui2_username;
internal LPWSTR ui2_domainname;
}
[DllImport("NetApi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern NET_API_STATUS NetUseAdd(
LPWSTR UncServerName,
DWORD Level,
ref USE_INFO_2 Buf,
out DWORD ParmError);
private Boolean netUseWithCredentials()
{
uint returncode;
try
{
USE_INFO_2 useinfo = new USE_INFO_2();
useinfo.ui2_remote = uncPath;
useinfo.ui2_username = user.username;
useinfo.ui2_domainname = user.domain;
useinfo.ui2_password = user.password;
useinfo.ui2_asg_type = 0;
useinfo.ui2_usecount = 1;
uint paramErrorIndex;
returncode = NetUseAdd(null, 2, ref useinfo, out paramErrorIndex);
prevError = (int)returncode;
if(prevError != 0)
Logger.logText("UNCAccess", "Fehler: Eine Verbindung zu " + uncPath + " konnte nicht aufgebaut werden: " + prevError + "," + paramErrorIndex + "!", true);
return returncode == 0;
}
catch(Exception ex)
{
prevError = Marshal.GetLastWin32Error();
Logger.log("UNCAccess", ex, "Fehler: Eine Verbindung zu " + uncPath + " konnte nicht aufgebaut werden: " + prevError + "!", 0);
return false;
}
}
所以基本上我们在“returncode = NetUseAdd(null, 2, ref useinfo, out paramErrorIndex);”中得到了返回码 1232行。
至于用户/密码/uncpath 变量,两台服务器使用完全相同的变量。
有人知道这里会发生什么吗?
【问题讨论】:
标签: c# unc network-drive net-use