Click here to Skip to main content
Licence CPOL
First Posted 4 Jun 2009
Views 7,251
Downloads 114
Bookmarked 8 times

A Quick Drive Manager

By | 4 Jun 2009 | Article
Connecting and disconnecting network drives

Introduction 

The project demonstrates the use of some useful network-API of Windows by connecting and disconnecting network shares.

Background 

This is very useful if anyone wants to handle network shares and assign and delete drive letters for it.

Using the Code 

The main focus lies on the Drives class which handles the networking tasks and its API. Useful is the ErrorText class by providing some error texts.

The Drives class encapsulates the API and works this way:

Connecting to a share:

DWORD dw = m_drives.ConnectionDialog1( m_csPath, &t );

//for deleting a drive letter (not its content)
DWORD dw = m_drives.DisConnect( m_csDrive );	

It hides some structs and its initializing with proper values: 

memset( &m_NetResource, 0, sizeof(m_NetResource) );
m_NetResource.dwScope = RESOURCE_REMEMBERED;
m_NetResource.dwType = RESOURCETYPE_DISK;
m_NetResource.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE;
m_NetResource.dwUsage = RESOURCEUSAGE_CONNECTABLE;
m_NetResource.lpLocalName = szDrive;//TEXT("Test");//
m_NetResource.lpRemoteName = (LPTSTR) pszPath;

CONNECTDLGSTRUCT dlg = {0};
dlg.cbStructure = sizeof(dlg);
dlg.hwndOwner = GetDesktopWindow();
dlg.lpConnRes = &m_NetResource;
dlg.dwFlags = CONNDLG_PERSIST|CONNDLG_USE_MRU;

Demonstration 

For real world use, I had conceptualised the class. I have provided a tiny MFC GUI.

I want to give the audience a look for what class is useable. With the open drive button, you can access the new drive. 

QDM_Main.jpg

Points of Interest  

Networking is a real huge area; this is only a little demonstration of two interesting tasks. There is a lot I could do to extend it. It would be interesting to enumerate findable shares and make them selectable. The desired drive letters didn't work on Vista.

History 

  • 2009/06/05: Initial release v0.9

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

KarstenK

Software Developer

Germany Germany

Member

I am living in germany and now living from programming for some Years. In my spare time I like sports as jogging, playing football (soccer) and basketball.
 
We must take care for our planet, because we and our family has no other. And everybody has to do something for it.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 Pinmemberdxlee3:52 6 Oct '09  
GeneralMy vote of 1 PinmemberMember 1657986:00 15 Jun '09  
GeneralRe: My vote of 1 PinmemberKarstenK21:15 17 Jun '09  
GeneralMy vote of 1 PinmemberCountry Man21:38 8 Jun '09  
GeneralRe: My vote of 1 PinmemberKarstenK21:14 17 Jun '09  

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.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 5 Jun 2009
Article Copyright 2009 by KarstenK
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid