Microsoft KB Archive/243627

= INFO: Disconnecting from a NetWare File Server by Using WNetCancelConnection2 API =

Article ID: 243627

Article Last Modified on 2/22/2007

-

APPLIES TO


 * Microsoft Windows 2000 Server
 * Microsoft Windows 2000 Advanced Server
 * Microsoft Windows 2000 Professional Edition
 * Microsoft Windows 98 Standard Edition
 * Microsoft Win32 Application Programming Interface
 * Microsoft Windows NT Server 4.0 Standard Edition
 * Microsoft Windows NT Workstation 4.0 Developer Edition

-



This article was previously published under Q243627



SUMMARY
Logging off and detaching from a NetWare file server by using the WNetCancelConnection2 function requires that you pass only the file server name as the resource name.

The connection type should be 0 (zero) and the force parameter should be set to True as shown in the following Visual Basic subroutines, Attach_FileServer and Detach_FileServer: Option Explicit

Declare Function WNetAddConnection2 Lib "mpr.dll" Alias _ "WNetAddConnection2A" (lpNetResource As NETRESOURCE, _ ByVal lpPassword As String, ByVal lpUserName As String, _ ByVal dwFlags As Long) As Long

Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias _ "WNetCancelConnection2A" (ByVal lpName As String, _ ByVal dwFlags As Long, ByVal fForce As Long) As Long

Type NETRESOURCE dwScope As Long dwType As Long dwDisplayType As Long dwUsage As Long lpLocalName As String lpRemoteName As String lpComment As String lpProvider As String End Type

Const NO_ERROR = 0 ' The following includes all the constants defined for NETRESOURCE, ' not just the ones used in this example. Const RESOURCETYPE_DISK = &H1 Const RESOURCE_GLOBALNET = &H2 Const RESOURCEDISPLAYTYPE_SHARE = &H3 Const RESOURCEUSAGE_CONNECTABLE = &H1

Sub Attach_FileServer Dim rc As Integer Dim NetR As NETRESOURCE Dim MyPass, MyUser As String NetR.dwScope = RESOURCE_GLOBALNET NetR.dwType = RESOURCETYPE_DISK NetR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE NetR.lpLocalName = "" ' If undefined, Connect with no device NetR.lpRemoteName = "\\FILE_SERVER" ' If the UserName and Password arguments are NULL, the user context ' for the process provides the default user name. MyUser = "Guest" MyPass = "guest" rc = WNetAddConnection2(NetR, MyPass, MyUser, 0) If (rc <> NO_ERROR) Then MsgBox "Error " & CStr(rc) & ": Cannot Attach to FileServer" Else MsgBox "Attached" End If End Sub

Sub Detach_FileServer Dim rc As Integer ' To disconnect from a NetWare server, we have to use just the ' file server name. rc = WNetCancelConnection2("\\FILE_SERVER", 0, True) If (rc <> NO_ERROR) Then MsgBox "Error " & CStr(rc) & ": Cannot Detach from FileServer" Else MsgBox "Detached" End If End Sub



MORE INFORMATION
To determine whether NetWare file servers are attached, right-click Network Neighborhood (or My Network Places), and then click Who am I. This action shows the servers that are currently attached. If you perform this action after the WNetAddConnection2function, the server that was attached to is displayed; after the WNetCancelConnection2 function, the server should not be present in the list.

