public static void MapDrive(IntPtr owner, String remotePath) {
if (String.IsNullOrEmpty(remotePath) || !PathIsNetworkPath(remotePath)) {
WNetConnectionDialog(owner, 1);
} else {
ConnectDialogInfo info = new ConnectDialogInfo();
info.Owner = owner;
info.Flags = ConnectDialogFlags.Persist | ConnectDialogFlags.ReadOnlyPath;
NETRESOURCE res = new NETRESOURCE();
res.dwType = ResourceType.RESOURCETYPE_DISK;
res.lpRemoteName = Marshal.StringToHGlobalAuto(remotePath);
IntPtr resptr = GlobalAlloc(0x0040 | 0x0000, (UIntPtr)Marshal.SizeOf(res));
CopyMemory(resptr, res, (uint)Marshal.SizeOf(res));
info.ConnectResource = resptr;
info.StructureSize = (uint)Marshal.SizeOf(info);
var result = WNetConnectionDialog1(info);
GlobalFree(resptr);
}
}