1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| [DllImport("mpr.dll")]
public static extern uint WNetAddConnection3(
[In]IntPtr hwndOwner,
[In]ref NETRESOURCE lpNetResource,
[In]string lpPassword,
[In]string lpUsername,
[In]WNetAddConnectionFlags dwFlags
);
[DllImport("mpr.dll")]
public static extern uint WNetCancelConnection2(
[In]string lpName,
[In]WNetCancelConnectionFlags dwFlags,
[In]bool fForce
);
// les méthodes de connexion disponibles
public static NetworkShare.NetworkShare ConnectDisk(string remoteName);
public static NetworkShare.NetworkShare ConnectDisk(string remoteName, PromptMode mode);
public static NetworkShare.NetworkShare ConnectDisk(string remoteName, IntPtr hwndOwner);
public static NetworkShare.NetworkShare ConnectDisk(string remoteName, PromptMode mode, IntPtr hwndOwner);
public static NetworkShare.NetworkShare ConnectDisk(string remoteName, string user, string pass);
public static NetworkShare.NetworkShare ConnectDisk(string remoteName, string user, string pass, PromptMode mode);
public static NetworkShare.NetworkShare ConnectDisk(string remoteName, string user, string pass, IntPtr hwndOwner);
public static NetworkShare.NetworkShare ConnectDisk(string remoteName, string user, string pass, PromptMode mode, IntPtr hwndOwner);
// la méthode qui effectue l'appel de WNetAddConnection3
private static NetworkShare ConnectDiskInternal(string remoteName, string user, string pass, NativeMethods.WNetAddConnectionFlags flags, IntPtr hwndOwner)
{
NetworkShare share = null;
try
{
uint ret;
NETRESOURCE netres = new NETRESOURCE();
netres.dwType = NETRESOURCE.Type.RESOURCETYPE_DISK;
netres.lpRemoteName = remoteName;
ret = NativeMethods.WNetAddConnection3(
hwndOwner,
ref netres,
pass,
user,
flags
);
if ( ret == NativeMethods.NO_ERROR )
{
share = new NetworkShare(remoteName);
}
else
{
share = null;
}
}
catch
{
share = null;
}
return share;
} |
Partager