NetUseAdd返回错误67或87

eya*_*yal 3 c# winapi

我正在调用NetApi32.dll方法NetUseAdd
这是这样的:

USE_INFO_2 useinfo = new USE_INFO_2();

useinfo.ui2_remote = UNCPath;
useinfo.ui2_username = User;
useinfo.ui2_domainname = Domain;
useinfo.ui2_password = Password;
useinfo.ui2_asg_type = 0;
useinfo.ui2_usecount = 1;
uint paramErrorIndex;
returncode = NetUseAdd(null, 2, ref useinfo, out paramErrorIndex);
Run Code Online (Sandbox Code Playgroud)

调用useinfo.ui2_remote = \\servername\dirname时返回代码67,调用useinfo.ui2_remote = \\servername\dirname\时返回代码87。

当我说它返回代码时...我的意思是要么抛出异常并Marshal.GetLastWin32Error()返回此错误代码,要么实际调用NetUseAdd返回它。

奇怪的是,此方法在使用没有 dub-folders 的路径调用时成功,而在使用具有子文件夹的路径调用时失败。

调用计算机是Windows Server 2008,而远程计算机是linux服务器(我不确定是哪个版本或发行版)。

知道如何才能成功连接\使用远程资源而不必担心子文件夹问题吗?

编辑

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
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);
Run Code Online (Sandbox Code Playgroud)

值得提及的更多信息:我尝试使用NetUseAdd添加的远程路径是一个巨大的存储(7 TB)。使用Windows资源管理器进行的简单访问大约需要3-4秒,但最终它会出现。

hma*_*gal 5

我不是这个主题的专家,但是我在使用类似的东西:

@"\\10.22.15.14\C$\Inetpub\wwwroot\db\archive\"
Run Code Online (Sandbox Code Playgroud)

我得到一个错误代码87,然后将字符串更改为

@"\\10.22.15.14\C$\Inetpub\wwwroot\db\archive"
Run Code Online (Sandbox Code Playgroud)

而且有效。也许,它可能对其他人有用。