Hi all I want to map a network drive. If the user has access to that
site then that path will map automatically. If the user doesnt have any rights
the i need to get the username and pwd from the user by using windows authentication screen. For example the
WNetConnectionD ialog shows the mapnetwork drive dialogbox.For example if you open an IE explorer and type the servername which you dont have access
In the mean while I found WNetAddConnecti on Function can be used to map that drive.
Here is the code I am using.But I am facing one problem
[CODE=vb]Option Explicit
Private m_WindowsUserNa me As String
Private m_NetworkPath As String
Private ErrInfo As Long
'Initialization of Varraibles
'Private Sub Class_Initializ e()
' MapDrive
'End Sub
Private Function MapDrive()
Dim NetR As NETRESOURCE
Dim MyPass As String, MyUser As String
NetR.dwScope = RESOURCE_GLOBAL NET
NetR.dwType = RESOURCETYPE_DI SK
NetR.dwDisplayT ype = RESOURCEDISPLAY TYPE_SHARE
NetR.dwUsage = RESOURCEUSAGE_C ONNECTABLE
NetR.lpLocalNam e = "X:" ' If undefined, Connect with no device
NetR.lpRemoteNa me = m_NetworkPath ' Your valid share
' If the MyPass and MyUser arguments are null (use vbNullString), the
' user context for the process provides the default user name.
ErrInfo = WNetAddConnecti on2(NetR, MyPass, MyUser, _
CONNECT_INTERAC TIVE Or CONNECT_PROMPT)
'CONNECT_INTERA CTIVE )
If ErrInfo = NO_ERROR Then
MsgBox "Net Connection Successful!", vbExclamation, "Share Connected"
Else
MsgBox GetErrorInfo, vbExclamation, "Share Not Connected"
End If
End Function
'Function get the Error description using Error Id
Private Function GetErrorInfo() As String
If ErrInfo = NO_ERROR Then
'If no Error do nothing
ElseIf ErrInfo = ERROR_CANCELLED Then
GetErrorInfo = "User Cancelled !"
ElseIf ErrInfo = ERROR_NO_NET_OR _BAD_PATH Then
GetErrorInfo = "Network Not Found !"
ElseIf ErrInfo = ERROR_NO_NETWOR K Then
GetErrorInfo = "Network Not Found !"
ElseIf ErrInfo = ERROR_DEVICE_AL READY_REMEMBERE D Then
GetErrorInfo = "The Network is Already Connect. Please disconnect it and try again !"
Else
GetErrorInfo = ErrInfo & " - Net Connection Failed!"
End If
If Len(GetErrorInf o) > 0 Then
GetErrorInfo = "ERROR : " & GetErrorInfo
End If
End Function
Public Property Get NetWorkPath() As String
NetWorkPath = m_NetworkPath
End Property
Public Property Let NetWorkPath(ByV al vNewValue As String)
m_NetworkPath = vNewValue
End Property
Public Function MapRemoteDrive( )
MapDrive
End Function [/CODE]
But Now I am facing one problem.Even If i have permision to that server it still prompting for username and password .I dont wy.I want to use the default username and password to map the drive.If it doesnt match, it has to dispay the
authentication window.Can some one Help
Thanks in advance
Dana
site then that path will map automatically. If the user doesnt have any rights
the i need to get the username and pwd from the user by using windows authentication screen. For example the
WNetConnectionD ialog shows the mapnetwork drive dialogbox.For example if you open an IE explorer and type the servername which you dont have access
In the mean while I found WNetAddConnecti on Function can be used to map that drive.
Here is the code I am using.But I am facing one problem
[CODE=vb]Option Explicit
Private m_WindowsUserNa me As String
Private m_NetworkPath As String
Private ErrInfo As Long
'Initialization of Varraibles
'Private Sub Class_Initializ e()
' MapDrive
'End Sub
Private Function MapDrive()
Dim NetR As NETRESOURCE
Dim MyPass As String, MyUser As String
NetR.dwScope = RESOURCE_GLOBAL NET
NetR.dwType = RESOURCETYPE_DI SK
NetR.dwDisplayT ype = RESOURCEDISPLAY TYPE_SHARE
NetR.dwUsage = RESOURCEUSAGE_C ONNECTABLE
NetR.lpLocalNam e = "X:" ' If undefined, Connect with no device
NetR.lpRemoteNa me = m_NetworkPath ' Your valid share
' If the MyPass and MyUser arguments are null (use vbNullString), the
' user context for the process provides the default user name.
ErrInfo = WNetAddConnecti on2(NetR, MyPass, MyUser, _
CONNECT_INTERAC TIVE Or CONNECT_PROMPT)
'CONNECT_INTERA CTIVE )
If ErrInfo = NO_ERROR Then
MsgBox "Net Connection Successful!", vbExclamation, "Share Connected"
Else
MsgBox GetErrorInfo, vbExclamation, "Share Not Connected"
End If
End Function
'Function get the Error description using Error Id
Private Function GetErrorInfo() As String
If ErrInfo = NO_ERROR Then
'If no Error do nothing
ElseIf ErrInfo = ERROR_CANCELLED Then
GetErrorInfo = "User Cancelled !"
ElseIf ErrInfo = ERROR_NO_NET_OR _BAD_PATH Then
GetErrorInfo = "Network Not Found !"
ElseIf ErrInfo = ERROR_NO_NETWOR K Then
GetErrorInfo = "Network Not Found !"
ElseIf ErrInfo = ERROR_DEVICE_AL READY_REMEMBERE D Then
GetErrorInfo = "The Network is Already Connect. Please disconnect it and try again !"
Else
GetErrorInfo = ErrInfo & " - Net Connection Failed!"
End If
If Len(GetErrorInf o) > 0 Then
GetErrorInfo = "ERROR : " & GetErrorInfo
End If
End Function
Public Property Get NetWorkPath() As String
NetWorkPath = m_NetworkPath
End Property
Public Property Let NetWorkPath(ByV al vNewValue As String)
m_NetworkPath = vNewValue
End Property
Public Function MapRemoteDrive( )
MapDrive
End Function [/CODE]
But Now I am facing one problem.Even If i have permision to that server it still prompting for username and password .I dont wy.I want to use the default username and password to map the drive.If it doesnt match, it has to dispay the
authentication window.Can some one Help
Thanks in advance
Dana