/* [DllImport("mpr.dll", CharSet = CharSet.Auto)] public static extern int WNetDisconnectDialog1(DisconnectDialogInfo disConnDlgStruct); */ 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); } }
public static extern int WNetConnectionDialog1(ConnectDialogInfo connDlgStruct);