Click here to Skip to main content
15,883,749 members
Articles / Desktop Programming / MFC

A Quick Drive Manager

Rate me:
Please Sign up or sign in to vote.
1.57/5 (5 votes)
4 Jun 2009CPOL 25.8K   672   10   5
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:

C++
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: 

C++
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)


Written By
Software Developer
Germany Germany
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.

Comments and Discussions

 
GeneralMy vote of 1 Pin
dxlee6-Oct-09 3:52
dxlee6-Oct-09 3:52 
GeneralMy vote of 1 Pin
Member 16579815-Jun-09 6:00
Member 16579815-Jun-09 6:00 
GeneralRe: My vote of 1 Pin
KarstenK17-Jun-09 21:15
mveKarstenK17-Jun-09 21:15 
GeneralMy vote of 1 Pin
Country Man8-Jun-09 21:38
Country Man8-Jun-09 21:38 
GeneralRe: My vote of 1 Pin
KarstenK17-Jun-09 21:14
mveKarstenK17-Jun-09 21:14 

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.