Cum enumar folderele din retea asociate unui drive local la care e conectat computerul (network drives)?
Raspuns
O metoda simpla este cu ajutorul functiei WNetGetConnection.
Exemplu
Code: Select all
#include <Windows.h>
#include <Winnetwk.h>
#include <tchar.h>
#include <iostream>
#pragma comment(lib, "Mpr.lib")
// ...
void ListNetworkDrives()
{
DWORD dwLength = 256;
TCHAR szLocalName[3] = {'\0', ':', '\0'};
TCHAR szRemoteName[256] = {0};
for(TCHAR chDrive = _T('a'); chDrive <= _T('z'); chDrive++)
{
szLocalName[0] = chDrive;
DWORD dwRet = ::WNetGetConnection(szLocalName, szRemoteName, &dwLength);
if(NO_ERROR == dwRet)
{
std::cout << "Local name: '" << szLocalName
<< "'\tremote name: '" << szRemoteName << "'" << std::endl;
}
else
{
// handle error; see WNetGetConnection documentation.
}
}
}
- [MSDN] WNetGetConnection Function
- [MSDN] Retrieving the Connection Name
- [WinAPI] Cum enumar drive-urile din sistem?
<< Back to Windows API Index