0
同じネットワーク上にある限り遠隔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);
}
FTPはおそらくこの種のものに適しています。 –
Windowsエクスプローラから手動で試しても問題ないですか? – Yahia
私は助けのために答えの人に感謝を見つけた。 – MStp