How to restore the original location of the established path?

In C ++, how can I find the location of a mounted drive? for example, if I mounted the drive s: c: \ temp (using subst on the command line) "subst c: \ temp s:" how can I get "c: \ temp" by passing "s:"

I would also like to know how this can be done for a network drive. (if s: is set to "\ MyComputer \ Hello", then I want to get "\ MyComputer \ Hello" and then extract from it "c: \ Hello"

This may be a very simple question, but I just could not find information about it.

Thanks,

Adam

+3
source share
3 answers

SUBST, API QueryDosDevice. SUBST, DefineDosDevice.

+1
0

To find the path to a connected network resource, you need to use the WNet API:

wstring ConvertToUNC(wstring sPath)
{
    WCHAR temp;
    UNIVERSAL_NAME_INFO * puni = NULL;
    DWORD bufsize = 0;
    wstring sRet = sPath;
    //Call WNetGetUniversalName using UNIVERSAL_NAME_INFO_LEVEL option
    if (WNetGetUniversalName(sPath.c_str(),
        UNIVERSAL_NAME_INFO_LEVEL,
        (LPVOID) &temp,
        &bufsize) == ERROR_MORE_DATA)
    {
        // now we have the size required to hold the UNC path
        WCHAR * buf = new WCHAR[bufsize+1];
        puni = (UNIVERSAL_NAME_INFO *)buf;
        if (WNetGetUniversalName(sPath.c_str(),
            UNIVERSAL_NAME_INFO_LEVEL,
            (LPVOID) puni,
            &bufsize) == NO_ERROR)
        {
            sRet = wstring(puni->lpUniversalName);
        }
        delete [] buf;
    }

    return sRet;;
} 
0
source

All Articles