Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

WNet provides two functions for retrieving a connection name: WNetGetUniversalNameand WNetGetConnection. WNetGetUniversalNametakes a drive-based path for a network connection and obtains a more universal name in the form of a data structure.

WNetGetConnectionenables an application to retrieve the name of a network resource associated with a local device. The following code example shows how WNetGetConnectionretrieves the network name of a local device called MyDevice.

Copy Code
TCHAR szDeviceName[80];
DWORD dwResult, 
	cchBuffer = sizeof (szDeviceName);

dwResult = WNetGetConnection (TEXT("MyDevice"), szDeviceName, 
							&cchBuffer);
switch (dwResult) 
{
  case ERROR_SUCCESS:
	MessageBox (hwnd, szDeviceName, TEXT("Info"), MB_OK);
	break;

  case ERROR_NOT_CONNECTED:
	MessageBox (hwnd, TEXT("MyDevice is not connected."), 
				TEXT("Info"), MB_OK);
	break;

  case ERROR_CONNECTION_UNAVAIL:
	// A connection is remembered, but not connected. 
	MessageBox (hwnd, TEXT("Connection unavailable."), 
				TEXT("Info"), MB_OK);
	break;

  default:
	ErrorHandler (hwnd, dwResult, TEXT("WNetGetConnection"));
	break;
} 

See Also