gpt4 book ai didi

c# - NetUseAdd 返回错误 67 或 87

转载 作者:行者123 更新时间:2023-11-30 14:32:50 26 4
gpt4 key购买 nike

我正在调用 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);

当使用 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);

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

最佳答案

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

@"\\10.22.15.14\C$\Inetpub\wwwroot\db\archive\"

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

@"\\10.22.15.14\C$\Inetpub\wwwroot\db\archive"

它奏效了。也许,它可能对其他人有用。

关于c# - NetUseAdd 返回错误 67 或 87,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17771489/

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