Click here to Skip to main content
Click here to Skip to main content

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, ...

Comments and Discussions

Questionfor vb6 Pinmemberafdoal18-Sep-11 2:30 
Questiondoes not work under win7 limited account PinmemberxRayen13-Sep-11 5:13 
QuestionError in using Map network drive API Pinmemberk.parvez31-Mar-11 22:14 
GeneralMy vote of 5 PinmemberJulijan Sribar18-Jan-11 0:02 
GeneralMy vote of 5 Pinmemberemirucan10-Jan-11 1:15 
GeneralThank you!!! PinmemberGuillermo Toro8-Dec-10 14:17 
GeneralLast version PinmemberMember 60274910-Feb-10 7:11 
GeneralRe: Last version PinmemberFaxedHead27-Feb-10 22:45 
GeneralRe: Last version PinmemberMember 6027491-Mar-10 8:40 
GeneralNew Version 0028 PinmemberTim Gladney5-Feb-10 4:42 
Generalthankssssssss PinmemberMember 28813132-Feb-10 1:01 
QuestionHow do you expand a mapped drive? PinmemberSparkyNZ26-Nov-09 9:30 
GeneralThis is an old version Pinmemberyrodrigu4-Nov-09 16:33 
GeneralLPT bug Pinmemberdmageiras11-Jun-09 2:09 
GeneralThank you PinmemberJosh Andy27-May-09 22:16 
GeneralNew patch makes it doesn't work any more on Windows 2003 Pinmembersongkai13-May-09 0:50 
GeneralServer OS 2003 PinmemberMember 456327911-May-09 12:00 
GeneralYour website is down Pinmembermm7777-May-09 23:20 
GeneralServer O/S Pinmembermbaocha4-May-09 17:14 
GeneralAttempt to access invalid address PinmemberMember 365220314-Dec-08 20:21 
GeneralRe: Attempt to access invalid address Pinmemberaejw14-Dec-08 21:19 
GeneralRe: Attempt to access invalid address PinmemberMember 365220315-Dec-08 7:01 
QuestionDo it once or everytime? What is the latest version? PinmemberKing-----Kong27-Nov-08 20:39 
AnswerRe: Do it once or everytime? What is the latest version? Pinmemberaejw14-Dec-08 20:59 
GeneralVista : Access denied PinmemberPierre Liétar12-Nov-08 1:08 
GeneralRe: Vista : Access denied Pinmemberaejw13-Nov-08 12:13 
Questionproblem using in an aspx button Pinmemberraziel782-Oct-08 1:58 
QuestionWorks on Windows XP Home? PinmemberHugo Tomas10-Jul-08 3:51 
AnswerRe: Works on Windows XP Home? Pinmemberaejw20-Jul-08 15:58 
QuestionHow do you install program Pinmemberchris guajardo18-Jun-08 11:50 
AnswerRe: How do you install program [modified] Pinmemberaejw19-Jun-08 12:59 
QuestionMultiple connections Exception PinmemberNickKa21-May-08 11:32 
AnswerRe: Multiple connections Exception Pinmemberaejw20-Jun-08 0:38 
GeneralRe: Multiple connections Exception PinmemberJosh Andy1-Jun-09 0:15 
GeneralMap netdriver error. [modified] PinmemberPaul Zhang16-Mar-08 17:24 
GeneralRe: Map netdriver error. Pinmemberaejw17-Mar-08 12:52 
GeneralRe: http webdrive (webdav) possible ? PinmemberMatterz11-Nov-07 2:09 
GeneralRe: http webdrive (webdav) possible ? Pinmemberaejw11-Nov-07 6:40 
GeneralRe: http webdrive (webdav) possible ? PinmemberMatterz26-Jan-08 18:31 
Questionhttp webdrive (webdav) possible ? PinmemberMatterz10-Nov-07 12:04 
AnswerRe: http webdrive (webdav) possible ? Pinmemberaejw10-Nov-07 18:54 
GeneralUnmapping Error PinmemberSturges9-Nov-07 6:12 
GeneralRe: Unmapping Error Pinmemberaejw10-Nov-07 19:00 
GeneralRe: Unmapping Error PinmemberSturges13-Nov-07 9:19 
GeneralThank you PinmemberMaYo6928-Sep-07 3:36 
GeneralUnMapDrive [modified] PinmemberDaniel B.18-Jun-07 6:55 
GeneralRe: UnMapDrive Pinmemberaejw20-Jun-07 19:36 
GeneralThanks Pinmemberspockxx113-Dec-06 6:44 
GeneralFor Update.... PinmemberSixcode29-Oct-06 3:47 
GeneralWorking with VB.NET [modified] Pinmemberdietercools10-Sep-06 13:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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
Web04 | 2.8.150129.1 | Last Updated 19 May 2004
Article Copyright 2004 by aejw
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid