To get mapped drives on Vista
- From: ybi10@xxxxxxxxx
- Date: Mon, 20 Apr 2009 12:19:17 -0700 (PDT)
This is in reply to Jialiang Ge at
http://groups.google.com/group/microsoft.public.win32.programmer.networks/browse_thread/thread/e6071602cf1911e2
What (or which API) is the right way to get mapped drives on Vista? I
used the following function to get mapped drives on Vista (please note
that I made the function as an exported dll function, and called the
function inside InstallShield script code), but it failed, the exact
the same code worked on XP. So my guess is that either the WNet...
APIs are not working on Vista, or InstallShield script has problem to
execute the APIs properly on Vista.
UINT WINAPI GetAllMappedDrives
(
char* szMapDrives // ......
)
{
static const int ILETTERLEN = 8;
static const int IDRIVEINFLEN = MAX_PATH*2;
DWORD ui = 0,ulBuf = 16384,ulEntries = 0xFFFFFFFF,ulErr =
0;
int iErr = 0;
HANDLE hEnum = 0;
LPNETRESOURCE pDrive = 0;
char cDriveInfo[IDRIVEINFLEN];
TCHAR tcRemoteName[MAX_PATH],tcProvider[MAX_PATH],tcLetter
[ILETTERLEN];
char* szDriveInfo = (char*)cDriveInfo;
char* szRemoteName = (char*)tcRemoteName;
char* szProvider = (char*)tcProvider;
char* szLetter = (char*)tcLetter;
ulErr = WNetOpenEnum(RESOURCE_CONNECTED,RESOURCETYPE_DISK,
0,0,&hEnum);
if (ulErr != NO_ERROR) return -5;
do {
pDrive = (LPNETRESOURCE)GlobalAlloc(GPTR,ulBuf);
ulErr = WNetEnumResource(hEnum,&ulEntries,pDrive,&ulBuf);
if (ulErr == NO_ERROR) {
iErr = ulEntries;
for (ui=0; ui<ulEntries; ui++) {
// Pull data out of resource structure.
sprintf_s(szLetter,ILETTERLEN,"%s",pDrive
[ui].lpLocalName);
if (!strcmp(szLetter,"(null)")) {
strcat_s(szLetter,ILETTERLEN,":");
}
sprintf_s(szRemoteName,MAX_PATH,"%s",pDrive
[ui].lpRemoteName);
sprintf_s(szProvider,MAX_PATH,"%s",pDrive
[ui].lpProvider);
// Copy the drive information.
strcpy_s(szDriveInfo,IDRIVEINFLEN,"?");
strcat_s(szDriveInfo,IDRIVEINFLEN,szLetter);
strcat_s(szDriveInfo,IDRIVEINFLEN,szRemoteName);
strcat_s(szDriveInfo,IDRIVEINFLEN,":");
strcat_s(szDriveInfo,IDRIVEINFLEN,szProvider);
strcat(szMapDrives,szDriveInfo);
}
} else if (ulErr != ERROR_NO_MORE_ITEMS) {
GlobalFree((HGLOBAL)pDrive);
iErr = -2;
break;
} else if (ulErr == ERROR_MORE_DATA) {
GlobalFree((HGLOBAL)pDrive);
iErr = -3;
break;
} else if (ulErr == ERROR_INVALID_HANDLE ||
ulErr == ERROR_NO_NETWORK ||
ulErr == ERROR_EXTENDED_ERROR) {
GlobalFree((HGLOBAL)pDrive);
iErr = -4;
break;
}
GlobalFree((HGLOBAL)pDrive);
} while (ulErr != ERROR_NO_MORE_ITEMS);
WNetCloseEnum(hEnum);
return iErr;
}
Please advice.
Thanks,
Peter
.
- Follow-Ups:
- Re: To get mapped drives on Vista
- From: JJ
- Re: To get mapped drives on Vista
- Prev by Date: WlanSetProfile returns 1206 (reposted as requested by Microsoft)
- Next by Date: Re: GetIfTable Overflow
- Previous by thread: WlanSetProfile returns 1206 (reposted as requested by Microsoft)
- Next by thread: Re: To get mapped drives on Vista
- Index(es):
Relevant Pages
|