Private Function unmap_drives(disconnect As Boolean) As Boolean
On Error GoTo err
Dim Ret As Long
Dim Drive1 As String
Dim WshNetwork
Dim strmain As String
Dim LDs
Dim SDrive1
Dim disconnectit
Dim drives As String
Dim fsodrive As New FileSystemObject
Dim driveletter1 As String
LDs = fGetDrives
Set WshNetwork = CreateObject("WScript.Network")
SDrive1 = Split(LDs, "\" & vbNullChar) 'get all the drives avaliable
Dim i As Long
For i = LBound(SDrive1) To UBound(SDrive1) 'loop though the drives
If SDrive1(i) <> "" Then
Drive1 = SDrive1(i)
If GetDriveType(Drive1) = 4 Then 'if it is a mapped drive
'Where H: is the drive letter you wish to connect
'The second parameter of this API determines whether to disconnect the drive if
'there are files open on it. If it is passed FALSE, the disconnect will fail if there are open files
'If it is passed TRUE, the disconnect will occur no matter what is open on the drive
If disconnect = True Then
disconnectit = WNetCancelConnection(Drive1, True) 'disconnect the drive
Else
drives = Drive1 & fsodrive.GetDrive(Drive1).ShareName 'to display the drives
txtstatus.Text = drives & vbCrLf & txtstatus.Text
End If
End If
End If
Next
Sleep (100)
unmap_drives = True
'End If
Exit Function
err:
If err.Number <> 0 Then
If err.Number = -2147024811 Then
MsgBox "The local device name is already in use.Please Disconnect and Run WMS", vbInformation
unmap_drives = False
Else
MsgBox err.Description, vbInformation
unmap_drives = False
End If
End If
End Function
Public Function fGetDrives() As String
'Returns all mapped drives
Dim lngRet As Long
Dim strDrives As String * 255
Dim lngTmp As Long
lngTmp = Len(strDrives)
lngRet = GetLogicalDriveStrings(lngTmp, strDrives)
fGetDrives = Left(strDrives, lngRet)
End Function
Private Function RunProgram(servername As String, custcode As String, Production As String, Exename As String)
On Error GoTo Err1
Dim Exepath As String
Dim fso As New FileSystemObject
Exepath = servername & "\" & custcode & "_" & Production & "\" & Exename
MsgBox Exepath
If fso.FileExists(Exepath) Then
MsgBox Exepath & " :- File Not Found"
Else
Shell Exepath, vbNormalFocus
End If
'cboMapServer.Text, cboCusCode.Text, validtester, "_Production"
Exit Function
Err1:
MsgBox err.Description
Exit Function
End Function