Click here to Skip to main content
13,860,780 members
Click here to Skip to main content
Add your own
alternative version


131 bookmarked
Posted 24 Apr 2004
Licenced CC (ASA 2.5)

Map Network Drive (API)

, 18 May 2004
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

QuestionConnecting to web-server Pin
Member 80103946-Sep-14 9:55
memberMember 80103946-Sep-14 9:55 
NewsI mentioned you! Pin
Antonio Petricca4-Oct-13 0:37
memberAntonio Petricca4-Oct-13 0:37 
QuestionHow Do I determine whether the specified drive is currently connected or not Pin
Prashant Bangaluru8-May-13 4:29
memberPrashant Bangaluru8-May-13 4:29 
Questionpublished version? Pin
fanff30001-Jan-13 19:05
memberfanff30001-Jan-13 19:05 
QuestionYour help needed Pin
Steve Ween2-Nov-12 14:17
memberSteve Ween2-Nov-12 14:17 
Questionaejw network Pin
tari_mrv1-Oct-12 3:18
membertari_mrv1-Oct-12 3:18 
QuestionAsking for credentials even if I supply them in Windows 7. Pin
Mike Miller9-Aug-12 13:27
memberMike Miller9-Aug-12 13:27 
QuestionLatest version Pin
jeremycafe111129-Apr-12 4:09
memberjeremycafe111129-Apr-12 4:09 
QuestionUnused drive letter Pin
Ross Chang31-Oct-11 19:47
memberRoss Chang31-Oct-11 19:47 
QuestionSite Pin
nenadvuckovic24-Oct-11 4:48
membernenadvuckovic24-Oct-11 4:48 
Questionfor vb6 Pin
afdoal18-Sep-11 2:30
memberafdoal18-Sep-11 2:30 
Questiondoes not work under win7 limited account Pin
xRayen13-Sep-11 5:13
memberxRayen13-Sep-11 5:13 
QuestionError in using Map network drive API Pin
k.parvez31-Mar-11 22:14
memberk.parvez31-Mar-11 22:14 
GeneralMy vote of 5 Pin
Julijan Sribar18-Jan-11 0:02
memberJulijan Sribar18-Jan-11 0:02 
GeneralMy vote of 5 Pin
emirucan10-Jan-11 1:15
memberemirucan10-Jan-11 1:15 
GeneralThank you!!! Pin
Guillermo Toro8-Dec-10 14:17
memberGuillermo Toro8-Dec-10 14:17 
GeneralLast version Pin
Member 60274910-Feb-10 7:11
memberMember 60274910-Feb-10 7:11 
GeneralRe: Last version Pin
FaxedHead27-Feb-10 22:45
memberFaxedHead27-Feb-10 22:45 
GeneralRe: Last version Pin
Member 6027491-Mar-10 8:40
memberMember 6027491-Mar-10 8:40 
GeneralNew Version 0028 Pin
Tim Gladney5-Feb-10 4:42
memberTim Gladney5-Feb-10 4:42 
Generalthankssssssss Pin
Member 28813132-Feb-10 1:01
memberMember 28813132-Feb-10 1:01 
QuestionHow do you expand a mapped drive? Pin
SparkyNZ26-Nov-09 9:30
memberSparkyNZ26-Nov-09 9:30 
GeneralThis is an old version Pin
Yvan Rodrigues4-Nov-09 16:33
professionalYvan Rodrigues4-Nov-09 16:33 
GeneralLPT bug Pin
dmageiras11-Jun-09 2:09
memberdmageiras11-Jun-09 2:09 
GeneralThank you Pin
Rami Shareef27-May-09 22:16
memberRami Shareef27-May-09 22:16 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190214.1 | Last Updated 19 May 2004
Article Copyright 2004 by aejw
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid