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 );
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;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.
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