Recent Posts

Sunday, March 9, 2008

How to Map Drive from Visual Basic 6.0??

How to Map Drive from Visual Basic 6.0??


'Use Reference Windows Script Host Object Model


Public Function MapDrive() As Boolean

Dim drive_letter As String
Dim share_name As String
Dim Password As String
Dim objND As New WshNetwork
On Error GoTo MErr
DoEvents
drive_letter = "X:"

share_name = "file://192.168.10.1/FolderName"
Password = "xyz@password"
objND.MapNetworkDrive drive_letter, share_name, , "userName", Password

MapDrive = True
Set objND = Nothing
Exit Function
MErr:
DisConnect
err.description
Set objND = Nothing
MapDrive = False
Exit Function
End Function



'For Disconnecting


Public Sub DisConnect()

Dim i As Long
Dim objND As New WshNetwork
On Error GoTo DErr
' close the connection with force -> 1
objND.RemoveNetworkDrive "X:"
Set objND = Nothing

Exit Sub
DErr:
Set objND = Nothing
err.description
End Sub

Related Posts by Categories




No comments:

Post a Comment