Private Sub MapDrive(ByVal strDriveLetter As String, _
ByVal strShare As String, _
Optional ByVal bPersistent As Boolean = True)
If strDriveLetter.Length = 1 AndAlso _
IO.Directory.Exists(strShare) Then
Dim strShellCommand, strPersistent As String
If bPersistent Then
strPersistent = "Yes"
Else
strPersistent = "No"
End If
strShellCommand = "NET USE " & strDriveLetter & _
": " & strShare & _
" /PERSISTENT:" & strPersistent
'shell out the command and
'wait for up to 1 minute
Shell(strShellCommand, AppWinStyle.Hide, True, 60000)
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
MapDrive("G", "\\ComputerName\ShareName", False)
End Sub