擷取連線名稱
若要擷取與本機裝置相關聯的網路資源名稱,應用程式可以呼叫 WNetGetConnection 函式,如下列範例所示。
下列範例會呼叫應用程式定義的錯誤處理常式來處理錯誤,以及用於列印的 TextOut 函式。
TCHAR szDeviceName[80];
DWORD dwResult, cchBuff = sizeof(szDeviceName);
// Call the WNetGetConnection function.
//
dwResult = WNetGetConnection(_T("z:"),
szDeviceName,
&cchBuff);
switch (dwResult)
{
//
// Print the connection name or process errors.
//
case NO_ERROR:
printf("Connection name: %s\n", szDeviceName);
break;
//
// The device is not a redirected device.
//
case ERROR_NOT_CONNECTED:
printf("Device z: not connected.\n");
break;
//
// The device is not currently connected, but it is a persistent connection.
//
case ERROR_CONNECTION_UNAVAIL:
printf("Connection unavailable.\n");
break;
//
// Handle the error.
//
default:
printf("WNetGetConnection failed.\n");
}
如需使用應用程式定義錯誤處理常式的詳細資訊,請參閱 擷取網路錯誤。
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應