To retrieve the name of the user that is associated either with a local device that is connected to a network resource or with the name of a network, an application can call the WNetGetUser function. The following code fragment uses the device name to retrieve the name of the user:
CHAR achUserName[80];
DWORD dwResult, cchBuff = sizeof(achUserName);
dwResult = WNetGetUser("z:",
(LPSTR) achUserName,
&cchBuff);
if(dwResult == NO_ERROR)
TextOut(hdc, 10, 10,
(LPSTR) achUserName,
lstrlen((LPSTR) achUserName));
else {
ErrorHandler(hwnd, dwResult, "WNetGetUser");
return FALSE;
}