To get mapped drives on Vista



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
.



Relevant Pages

  • Re: How do you wintrolls...
    ... This is much less a problem on a Mac, since you can't really tweak anything, and there's hardly any software for that, anyway. ... Vista's re-arranged explorer UI does make sense in its way. ... In Vista, it's functions have into a bunch of different places now, often with a richer UI to boot. ... Forget the menu bar and the mapped drives; it'll serve you better if you do. ...
    (comp.sys.mac.advocacy)
  • Re: SendKeys under Windows Vista with VB3
    ... 32-bit apis. ... The old 16 bit User library is definitely no longer provided in Vista, and if VB3 cannot use the 32 bit library then the OP cannot of course use the KeyBd event or indeed any other API funcion, which also rules out subclassing the keyboard, which is the other method I might have suggested. ... And if he wants to also allow the equivalent of Shift Tab then he can test for the Shift key in the Keyown event. ...
    (microsoft.public.vb.general.discussion)
  • Re: Sidebar-Elemente verschieben sich selber
    ... Vista ist wohl doch nicht so ausgereift... ... ja, die script engine der Vista-Sidebar hat eine ganze Menge Fehler. ... ob der Effekt auftritt, kann dann u.a. auch von den Interna der Sidebar-Gadgets abhängen, die bestimmte APIs aufrufen. ... Da gehört dann schon einiges an Erfahrungen zu, die Gadgets sauber und weitgehend fehlertolerant zu entwickeln. ...
    (microsoft.public.de.windows.vista.sonstiges)
  • Re: from elsewhere, an assembler
    ... want to take advantage of the new APIs for some reason. ... almost every OS upgrade I've seen (including Vista, ... the APIsfor the device drivers changed. ... parallel port. ...
    (alt.lang.asm)
  • Re: Vista and .NET (Win32 life may be limted)
    ... the Vista APIs otherwise). ... said, be aware that it is unlikely that Vista will not run Win16 apps, my ... such as "(Win32 life may be limited)" you should visit the ...
    (borland.public.delphi.non-technical)