Bagikan melalui


Mengambil Nama Koneksi

Untuk mengambil nama sumber daya jaringan yang terkait dengan perangkat lokal, aplikasi dapat memanggil fungsiWNetGetConnection, seperti yang ditunjukkan dalam sampel berikut.

Sampel berikut memanggil penangan kesalahan yang didefinisikan oleh aplikasi untuk memproses kesalahan, dan menggunakan fungsi TextOut untuk pencetakan.

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"); 
}

Untuk informasi selengkapnya tentang menggunakan penangan kesalahan yang ditentukan oleh aplikasi, lihat Mengambil Kesalahan Jaringan.