Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"No Disk" error when checking network drives

Status
Not open for further replies.

GomezAddamz

Technical User
Jan 23, 2008
26
0
0
US
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
 
turn on error resume next off to see where errors occur.
 
drvMAP also is preset to FALSE outside the loop. if it ever trips TRUE it will stay TRUE throughout the loop.
 
> if it ever trips TRUE it will stay TRUE throughout the loop.
Yes, thats the point of the loop; set it to True if "drivePath" is found mapped to "driveLetter". I don't see any logic problems in that part.

I do agree about removing the On Error Resume Next. GomezAddamz: Do you know which line of code executes when it tries to access the optical drive?
 
No, I do not. I presume it's inside the "For i = 0 to WshDrives.Count - 1 Step 2" as that's the only time it would be accessing the D drive.

I only use "On Error Resume Next" during the actual mapping, and then I use it to report if there are any errors with the mapping. I turn it off right after that, which I believe is redundant as my understanding is the scope of the "On Error Resume Next" statement ends with the function.

Unfortunately, this has proven to be a seemingly random and intermittent issue. I went to troubleshoot on a system only to learn the user wasn't getting the error any more. Next time it pops up I'll see if I can figure out exactly where the error is occurring in the script.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top