GomezAddamz
Technical User
Hello! I have a script that will check network drive mappings and create/modify them as needed. The problem is that some users are getting the following error: "There is no disk in the drive. Please insert a disk into drive D:." There are options to Cancel, Try Again, and Continue. None of the options will not clear the error. I have to kill wscript in task manager to make the error box go away. The D: drive is the optical drive on these systems, which is not one of the drive letters I am trying to map to (I am using X and Y). I would expect my code would only access network drives, but it seems that may not be the case. Any thoughts on why I'm seeing this error, and how to make it stop?
Code:
Option Explicit
Dim WshNetwork, WshDrives, drvLtr, drvPath, drvUpd, drvUsr, drvPass
Set WshNetwork = CreateObject("WScript.Network")
Set WshDrives = WshNetwork.EnumNetworkDrives
'Set variables for mapping
DriveMap drvLtr, drvPath, drvUpd, drvUsr, drvPass
Function DriveMap(driveLetter, drivePath, driveUpdate, driveUser, drivePass)
Dim drvExists, drvMap, i
drvExists = False
drvMap = False
For i = 0 to WshDrives.Count - 1 Step 2
If WshDrives.Item(i) = driveLetter Then
drvExists = TRUE
If WshDrives.Item(i+1) = drivePath Then
drvMap = TRUE
End If
End If
Next
If Not drvMap Then
If drvExists Then
WshNetwork.RemoveNetworkDrive driveLetter, TRUE, TRUE
End If
On Error Resume Next
WshNetwork.MapNetworkDrive driveLetter, drivePath, driveUpdate, driveUser, drivePass
If Err <> 0 Then
WScript.Echo "Could not map " & drivePath & " to " & driveLetter & " drive. " & Err.Description
Err.Clear
End If
On Error GoTo 0
End If
End Function