Click here to Skip to main content
12,255,255 members (62,392 online)
Click here to Skip to main content
Add your own
alternative version


125 bookmarked

Map Network Drive (API)

, 18 May 2004 CC (ASA 2.5)
Rate this:
Please Sign up or sign in to vote.
Class for interfacing to the "map network drive" windows interface

Image - netdrive0015.jpg

What does it do?

This is a class for interfacing with windows map network drive API's.

Introduction to the class...

  • Getting started

    Add the class file "cNetworkDrives0015.cs" to your project / solution.
    Add the "using" definition to your form, etc.
    using aejw.Network;
  • Example (Mapping a network drive)

    NetworkDrive oNetDrive = new aejw.Network.NetworkDrive();
       oNetDrive.LocalDrive = "m:";
       oNetDrive.ShareName = "\\ComputerName\Share"
    }catch(Exception err){
       MessageBox.Show(this,"Error: "+err.Message);
    oNetDrive = null;
  • Example (Unmapping a network drive)

    NetworkDrive oNetDrive = new aejw.Network.NetworkDrive();
       oNetDrive.LocalDrive = "m:";
    }catch(Exception err){
       MessageBox.Show(this,"Error: "+err.Message);
    oNetDrive = null;

Username and Password functions...

The following examples require the object / class to be declared.
cNetworkDrive oNetDrive = new cNetworkDrive();
  • Mapping a network drive

    • //Map drive with current user credentials
      oNetDrive.LocalDrive = "m:";
      oNetDrive.ShareName = "\\ComputerName\Share1"
    • //Map drive with specified user credentials
      oNetDrive.LocalDrive = "m:";
      oNetDrive.ShareName = "\\ComputerName\Share1"
    • //Map drive with and prompt user for credentials
      oNetDrive.LocalDrive = "m:";
      oNetDrive.ShareName = "\\ComputerName\Share1"
      oNetDrive.PromptForCredentials = true;
    • //Map drive using a persistent connection
      oNetDrive.LocalDrive = "m:";
      oNetDrive.Persistent = true;
      oNetDrive.SaveCredentials = true;
      oNetDrive.ShareName = "\\ComputerName\Share1"
  • Unmapping a network drive

    • //Unmap a network connection
      oNetDrive.LocalDrive = "m:";
      oNetDrive.ShareName = "\\ComputerName\Share1"
    • //Unmap a network connection ignoring network related errors
      oNetDrive.LocalDrive = "m:";
      oNetDrive.Force = true;
      oNetDrive.ShareName = "\\ComputerName\Share1"
  • Other functions

    • //Display windows connection dialog
      //Display windows disconnection dialog
    • //Restore all persistent connections


  • 14th May 2004 - build0015
    • LocalDrive and ShareName are now properties.
    • Dialog functions now use a form object instead of a window handle.
    • Renaming scheme for public functions and properties, MapNetworkDrive(...) is now MapDrive(...), etc...
    • Added Persistant option, Used for reconnecting a drive at logon.
    • Added SaveCredentials option, Allows windows to remember the user credentials when reconnecting a persistent connection.
    • Added Force option, for MapDrive calls, if a drive is connected it will disconnect that drive then reconnect to the new share.
    • Added PromptForCredintals option, for MapDrive calls, windows will ask for a username and password to use with the connection.
    • Added RestoreDrives function that restores persistent connections.
  • 30th April 2004 - build0012
    • Code refinements and tidying, added comments to the class.
  • 27th April 2004 - build0011
    • Adjusted declare tags, tidied class and article
  • 26th April 2004 - build0010
    • First version posted online


This article, along with any associated source code and files, is licensed under The Creative Commons Attribution-ShareAlike 2.5 License


About the Author

Web Developer
New Zealand New Zealand
C#, (Web and forms), SQL Server, MySQL, ASP, Win32 API, ...

You may also be interested in...

Comments and Discussions

Questionfor vb6 Pin
afdoal18-Sep-11 1:30
memberafdoal18-Sep-11 1:30 
Questiondoes not work under win7 limited account Pin
xRayen13-Sep-11 4:13
memberxRayen13-Sep-11 4:13 
QuestionError in using Map network drive API Pin
k.parvez31-Mar-11 21:14
memberk.parvez31-Mar-11 21:14 
GeneralMy vote of 5 Pin
Julijan Sribar17-Jan-11 23:02
memberJulijan Sribar17-Jan-11 23:02 
GeneralMy vote of 5 Pin
emirucan10-Jan-11 0:15
memberemirucan10-Jan-11 0:15 
GeneralThank you!!! Pin
Guillermo Toro8-Dec-10 13:17
memberGuillermo Toro8-Dec-10 13:17 
GeneralLast version Pin
Member 60274910-Feb-10 6:11
memberMember 60274910-Feb-10 6:11 
GeneralRe: Last version Pin
FaxedHead27-Feb-10 21:45
memberFaxedHead27-Feb-10 21:45 
GeneralRe: Last version Pin
Member 6027491-Mar-10 7:40
memberMember 6027491-Mar-10 7:40 
GeneralNew Version 0028 Pin
Tim Gladney5-Feb-10 3:42
memberTim Gladney5-Feb-10 3:42 
Generalthankssssssss Pin
Member 28813132-Feb-10 0:01
memberMember 28813132-Feb-10 0:01 
QuestionHow do you expand a mapped drive? Pin
SparkyNZ26-Nov-09 8:30
memberSparkyNZ26-Nov-09 8:30 
GeneralThis is an old version Pin
yrodrigu4-Nov-09 15:33
memberyrodrigu4-Nov-09 15:33 
GeneralLPT bug Pin
dmageiras11-Jun-09 1:09
memberdmageiras11-Jun-09 1:09 
GeneralThank you Pin
Josh Andy27-May-09 21:16
memberJosh Andy27-May-09 21:16 
GeneralNew patch makes it doesn't work any more on Windows 2003 Pin
songkai12-May-09 23:50
membersongkai12-May-09 23:50 
GeneralServer OS 2003 Pin
Member 456327911-May-09 11:00
memberMember 456327911-May-09 11:00 
GeneralYour website is down Pin
mm7777-May-09 22:20
membermm7777-May-09 22:20 
GeneralServer O/S Pin
mbaocha4-May-09 16:14
membermbaocha4-May-09 16:14 
GeneralAttempt to access invalid address Pin
Member 365220314-Dec-08 19:21
memberMember 365220314-Dec-08 19:21 
GeneralRe: Attempt to access invalid address Pin
aejw14-Dec-08 20:19
memberaejw14-Dec-08 20:19 
GeneralRe: Attempt to access invalid address Pin
Member 365220315-Dec-08 6:01
memberMember 365220315-Dec-08 6:01 
QuestionDo it once or everytime? What is the latest version? Pin
King-----Kong27-Nov-08 19:39
memberKing-----Kong27-Nov-08 19:39 
AnswerRe: Do it once or everytime? What is the latest version? Pin
aejw14-Dec-08 19:59
memberaejw14-Dec-08 19:59 
GeneralVista : Access denied Pin
Pierre Liétar12-Nov-08 0:08
memberPierre Liétar12-Nov-08 0:08 
GeneralRe: Vista : Access denied Pin
aejw13-Nov-08 11:13
memberaejw13-Nov-08 11:13 
Questionproblem using in an aspx button Pin
raziel782-Oct-08 0:58
memberraziel782-Oct-08 0:58 
QuestionWorks on Windows XP Home? Pin
Hugo Tomas10-Jul-08 2:51
memberHugo Tomas10-Jul-08 2:51 
AnswerRe: Works on Windows XP Home? Pin
aejw20-Jul-08 14:58
memberaejw20-Jul-08 14:58 
QuestionHow do you install program Pin
chris guajardo18-Jun-08 10:50
memberchris guajardo18-Jun-08 10:50 
AnswerRe: How do you install program [modified] Pin
aejw19-Jun-08 11:59
memberaejw19-Jun-08 11:59 
QuestionMultiple connections Exception Pin
NickKa21-May-08 10:32
memberNickKa21-May-08 10:32 
AnswerRe: Multiple connections Exception Pin
aejw19-Jun-08 23:38
memberaejw19-Jun-08 23:38 
GeneralRe: Multiple connections Exception Pin
Josh Andy31-May-09 23:15
memberJosh Andy31-May-09 23:15 
GeneralMap netdriver error. [modified] Pin
Paul Zhang16-Mar-08 16:24
memberPaul Zhang16-Mar-08 16:24 
GeneralRe: Map netdriver error. Pin
aejw17-Mar-08 11:52
memberaejw17-Mar-08 11:52 
GeneralRe: http webdrive (webdav) possible ? Pin
Matterz11-Nov-07 1:09
memberMatterz11-Nov-07 1:09 
GeneralRe: http webdrive (webdav) possible ? Pin
aejw11-Nov-07 5:40
memberaejw11-Nov-07 5:40 
GeneralRe: http webdrive (webdav) possible ? Pin
Matterz26-Jan-08 17:31
memberMatterz26-Jan-08 17:31 
Questionhttp webdrive (webdav) possible ? Pin
Matterz10-Nov-07 11:04
memberMatterz10-Nov-07 11:04 
AnswerRe: http webdrive (webdav) possible ? Pin
aejw10-Nov-07 17:54
memberaejw10-Nov-07 17:54 
GeneralUnmapping Error Pin
Sturges9-Nov-07 5:12
memberSturges9-Nov-07 5:12 
GeneralRe: Unmapping Error Pin
aejw10-Nov-07 18:00
memberaejw10-Nov-07 18:00 
GeneralRe: Unmapping Error Pin
Sturges13-Nov-07 8:19
memberSturges13-Nov-07 8:19 
GeneralThank you Pin
MaYo6928-Sep-07 2:36
memberMaYo6928-Sep-07 2:36 
GeneralUnMapDrive [modified] Pin
Daniel B.18-Jun-07 5:55
memberDaniel B.18-Jun-07 5:55 
GeneralRe: UnMapDrive Pin
aejw20-Jun-07 18:36
memberaejw20-Jun-07 18:36 
GeneralThanks Pin
spockxx113-Dec-06 5:44
memberspockxx113-Dec-06 5:44 
GeneralFor Update.... Pin
Sixcode29-Oct-06 2:47
memberSixcode29-Oct-06 2:47 
GeneralWorking with VB.NET [modified] Pin
dietercools10-Sep-06 12:58
memberdietercools10-Sep-06 12:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160426.1 | Last Updated 19 May 2004
Article Copyright 2004 by aejw
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid