WNetUseConnection连接到同一个域上的远程服务器/ UNC,但不连接到另一个/远程域
问题描述:
只要它位于同一网络上,我可以连接到远程UNC,但是当我尝试跨域访问服务器时,请说从网络A到网络B,它没有连接,我得到的消息没有找到网络路径。如何在不同/不可信网络上连接远程UNC。WNetUseConnection连接到同一个域上的远程服务器/ UNC,但不连接到另一个/远程域
[DllImport("Mpr.dll")]
private static extern int WNetUseConnection(
IntPtr hwndOwner,
NETRESOURCE lpNetResource,
string lpPassword,
string lpUserID,
int dwFlags,
string lpAccessName,
string lpBufferSize,
string lpResult
);
[DllImport("Mpr.dll")]
private static extern int WNetCancelConnection2(
string lpName,
int dwFlags,
bool fForce
);
[StructLayout(LayoutKind.Sequential)]
private class NETRESOURCE
{
public int dwScope = 0;
public int dwType = 0;
public int dwDisplayType = 0;
public int dwUsage = 0;
public string lpLocalName = null;//changed from "" to null
public string lpRemoteName = "";
public string lpComment = "";
public string lpProvider = null;//changed from "" to null
}
public static string connectToRemote(string remoteUNC, string username, string password)
{
return connectToRemote(remoteUNC, username, password, false);
}
public static string connectToRemote(string remoteUNC, string username, string password, bool promptUser)
{
NETRESOURCE nr = new NETRESOURCE();
nr.dwType = RESOURCETYPE_DISK;
nr.lpRemoteName =remoteUNC;
int ret;
if (promptUser)
ret = WNetUseConnection(IntPtr.Zero, nr, "", "", CONNECT_INTERACTIVE | CONNECT_PROMPT, null, null, null);
else
ret = WNetUseConnection(IntPtr.Zero, nr, password, username, 0, null, null, null);
if (ret == NO_ERROR) return null;
return getErrorForNumber(ret);
}
public static string disconnectRemote(string remoteUNC)
{
int ret = WNetCancelConnection2(remoteUNC, CONNECT_UPDATE_PROFILE, false);
if (ret == NO_ERROR) return null;
return getErrorForNumber(ret);
}
答
如果使用桌面排版,这将跨网络访问。
+2
你能解释桌面出版吗? – 2013-11-18 23:38:23
FTP可能更适合这类事情。 – 2012-03-12 17:43:48
如果从Windows资源管理器手动尝试,这是否可以工作? – Yahia 2012-03-12 17:59:47
我发现答案的人谢谢你的帮助。 – MStp 2012-03-12 18:17:50