Platform SDK: Windows Networking |
Windows NT/Windows 2000
The following example demonstrates how to call the WNetGetUniversalName function to determine the location of a share on a redirected drive.
First the code sample calls the WNetGetUniversalName function, specifying the UNIVERSAL_NAME_INFO information level to retrieve a pointer to a Universal Naming Convention (UNC) name string for the resource. Then the sample calls WNetGetUniversalName a second time, specifying the REMOTE_NAME_INFO information level to retrieve two additional network connection information strings. If the calls are successful, the sample prints the location of the share.
To test the following code sample, perform the following steps:
GetUni H:\ #define STRICT #include <windows.h> #include <stdio.h> #define BUFFSIZE = 1000 void main( int argc, char *argv[] ) { DWORD cbBuff = 1000 // Size of Buffer TCHAR szBuff[1000]; // Buffer to receive information REMOTE_NAME_INFO * prni = (REMOTE_NAME_INFO *) &szBuff; // Pointers to head of buffer UNIVERSAL_NAME_INFO * puni = (UNIVERSAL_NAME_INFO *) &szBuff; DWORD res; if((argc < 2) | (lstrcmp(argv[1], "/?") == 0)) { printf("Syntax: GetUni DrivePathAndFilename\n" "Example: GetUni U:\\WINNT\\SYSTEM32\\WSOCK32.DLL\n"); return; } // Call the WNetGetUniversalName function specifying the // UNIVERSAL_NAME_INFO_LEVEL option. // printf("Call WNetGetUniversalName using UNIVERSAL_NAME_INFO_LEVEL.\n"); if((res = WNetGetUniversalName((LPTSTR)argv[1], UNIVERSAL_NAME_INFO_LEVEL, // //The structure is written to this block of memory. // (LPVOID) &szBuff, &cbBuff)) != NO_ERROR) // // If the call fails, print the error; otherwise, print // the location of the share, // using the pointer to UNIVERSAL_NAME_INFO_LEVEL. // printf("Error: %ld\n\n", res); else printf("Universal Name: \t%s\n\n", puni->lpUniversalName); // // Call the WNetGetUniversalName function, // using the REMOTE_NAME_INFO_LEVEL option. // printf("Call WNetGetUniversalName using REMOTE_NAME_INFO_LEVEL.\n"); if((res = WNetGetUniversalName((LPTSTR)argv[1], REMOTE_NAME_INFO_LEVEL, (LPVOID) &szBuff, //Structure is written to this block of memory &cbBuff)) != NO_ERROR) // // If the call fails, print the error; otherwise, print // the location of the share, using // the pointer to REMOTE_NAME_INFO_LEVEL. // printf("Error: %ld\n", res); else printf("Universal Name: \t%s\n" "Connection Name:\t%s\n" "Remaining Path: \t%s\n", prni->lpUniversalName, prni->lpConnectionName, prni->lpRemainingPath); return; }