Re: From UNC pathname to driveletter
This will enumerate the local network maps and you can see what drive letter
is mapped to what share.
#pragma comment(lib, "Mpr.lib")
HANDLE handle;
if (::WNetOpenEnum(RESOURCE_CONNECTED, RESOURCETYPE_DISK,
RESOURCEUSAGE_ATTACHED, NULL, &handle) != NO_ERROR)
{
_tprintf(_T("Network Enumeration FAIL - Failed to retrieve connected
resources.\n"));
return 1;
}
DWORD cbBuffer = 16384;
LPNETRESOURCE lpnrLocal;
DWORD dwResultEnum;
DWORD cEntries = -1;
lpnrLocal = (LPNETRESOURCE)::GlobalAlloc(GPTR, cbBuffer);
if (lpnrLocal == NULL)
{
_tprintf(_T("Network Enumeration FAIL - Failed to allocate internal
buffer.\n"));
}else
{
do
{
// Initialize the buffer.
ZeroMemory(lpnrLocal, cbBuffer);
// Call the WNetEnumResource function to continue
// the enumeration
dwResultEnum = ::WNetEnumResource(handle,
&cEntries,
lpnrLocal,
&cbBuffer);
// If the call succeeds, loop through the structures.
if (dwResultEnum == NO_ERROR)
{
for (DWORD i = 0; i < cEntries; i++)
{
_tprintf(_T("Drive Letter: "));
if (lpnrLocal[i].lpLocalName == NULL)
{
_tprintf(_T("{not mapped}\n"));
}else
{
_tprintf(_T("%s\n"), lpnrLocal[i].lpLocalName);
}
_tprintf(_T("UNC: "));
if (lpnrLocal[i].lpRemoteName == NULL)
{
_tprintf(_T("{unknown}\n"));
}else
{
_tprintf(_T("%s\n"), lpnrLocal[i].lpRemoteName);
}
_tprintf(_T("Provider: "));
if (lpnrLocal[i].lpProvider == NULL)
{
_tprintf(_T("{unknown}\n"));
}else
{
_tprintf(_T("%s\n"), lpnrLocal[i].lpProvider);
}
_tprintf(_T("\n"));
}
}
} while(dwResultEnum != ERROR_NO_MORE_ITEMS);
::GlobalFree((HGLOBAL)lpnrLocal);
}
::WNetCloseEnum(handle);
"RAN" <nijenhuis@wish.nl> wrote in message
news:c39b88bd-85a2-4a46-91a9-a5c56e580012@p25g2000hsf.googlegroups.com...
Hello,
How do get the driveletter from an UNC pathname.
I am trying to read keys in a .ini file using
GetPrivateProfileString().
I selected the .ini file with CFileDialog, which returns the UNC
pathname.
I cant read it using UNC, if replace the UNC with the driveletter/
pathname it works.
Could not find any examples on the internet.