VB Code:
  1. Private Function unmap_drives(disconnect As Boolean) As Boolean
  2. On Error GoTo err
  3. Dim Ret As Long
  4. Dim Drive1 As String
  5. Dim WshNetwork
  6. Dim strmain As String
  7. Dim LDs
  8. Dim SDrive1
  9. Dim disconnectit
  10. Dim drives As String
  11. Dim fsodrive As New FileSystemObject
  12.  Dim driveletter1 As String
  13.     LDs = fGetDrives
  14.     Set WshNetwork = CreateObject("WScript.Network")
  15.      SDrive1 = Split(LDs, "\" & vbNullChar) 'get all the drives avaliable
  16.     Dim i As Long
  17.     For i = LBound(SDrive1) To UBound(SDrive1) 'loop though the drives
  18.        If SDrive1(i) <> "" Then
  19.             Drive1 = SDrive1(i)
  20.                 If GetDriveType(Drive1) = 4 Then 'if it is a mapped drive
  21.                         'Where H: is the drive letter you wish to connect
  22.                         'The second parameter of this API determines whether to disconnect the drive if
  23.                         'there are files open on it.   If it is passed FALSE, the disconnect will fail if there are open files
  24.                         'If it is passed TRUE, the disconnect will occur no matter what is open on the drive
  25.                     If disconnect = True Then
  26.                         disconnectit = WNetCancelConnection(Drive1, True) 'disconnect the drive
  27.                     Else
  28.                         drives = Drive1 & fsodrive.GetDrive(Drive1).ShareName 'to display the drives
  29.                         txtstatus.Text = drives & vbCrLf & txtstatus.Text
  30.                     End If
  31.                    
  32.                    
  33.                    
  34.                 End If
  35.           End If
  36.    Next
  37.     Sleep (100)
  38.    unmap_drives = True
  39.     'End If
  40.  
  41. Exit Function
  42. err:
  43.    
  44.     If err.Number <> 0 Then
  45.         If err.Number = -2147024811 Then
  46.             MsgBox "The local device name is already in use.Please Disconnect and Run WMS", vbInformation
  47.             unmap_drives = False
  48.         Else
  49.             MsgBox err.Description, vbInformation
  50.             unmap_drives = False
  51.         End If
  52.     End If
  53. End Function
  54.  
  55. Public Function fGetDrives() As String
  56. 'Returns all mapped drives
  57.     Dim lngRet As Long
  58.     Dim strDrives As String * 255
  59.     Dim lngTmp As Long
  60.     lngTmp = Len(strDrives)
  61.     lngRet = GetLogicalDriveStrings(lngTmp, strDrives)
  62.     fGetDrives = Left(strDrives, lngRet)
  63. End Function
  64. Private Function RunProgram(servername As String, custcode As String, Production As String, Exename As String)
  65.     On Error GoTo Err1
  66.     Dim Exepath As String
  67.     Dim fso As New FileSystemObject
  68.     Exepath = servername & "\" & custcode & "_" & Production & "\" & Exename
  69.     MsgBox Exepath
  70.     If fso.FileExists(Exepath) Then
  71.       MsgBox Exepath & " :- File Not Found"
  72.     Else
  73.       Shell Exepath, vbNormalFocus
  74.     End If
  75.     'cboMapServer.Text, cboCusCode.Text, validtester, "_Production"
  76. Exit Function
  77. Err1:
  78.      MsgBox err.Description
  79.      Exit Function
  80. End Function