Share via


Terminating a Network Connection (Windows Embedded CE 6.0)

1/6/2010

An application can use the following functions to terminate network connections: WNetDisconnectDialog, WNetDisconnectDialog1, or WNetCancelConnection2. The WNetDisconnectDialog displays a dialog box listing all currently connected resources and permits user to select which resources to disconnect from. WNetDisconnectDialog1 attempts to disconnect from a network and notifies the user of any errors presents. WNetCancelConnection2 enables applications to disconnect from network resources and can be used to remove remembered network connections not currently in use. The following code example shows how WNetCancelConnection2 is used to disconnect from a network resource called MyDevice.

DWORD dwResult;

dwResult = WNetCancelConnection2 (
                TEXT("MyDevice"),       // Device name.
                CONNECT_UPDATE_PROFILE, // Remove persistent connection.
                FALSE);                 

if (dwResult == ERROR_NOT_CONNECTED)
{
  MessageBox (hwnd, TEXT("MyDevice is not connected."), 
              TEXT("Info"), MB_OK);
  return FALSE;
}
else if (dwResult != ERROR_SUCCESS)
{
  ErrorHandler (hwnd, dwResult, TEXT("WNetCancelConnection2"));
  return FALSE;
}

MessageBox (hwnd, TEXT("Connection closed for MyDevice"), 
            TEXT("Info"), MB_OK); 

See Also

Concepts

Connecting to a Network
Windows Networking API/Redirector Application Development