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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Logon Script Help

Status
Not open for further replies.

creiners

IS-IT--Management
Jun 16, 2004
8
US
I have a logon script that I am really stumped on.

This code worked for well over 2 years and has not been changed. Suddenly it has randomly stopped working on computers in my domain. Some are W2k some are XP. The script sends me no errors even when I try to turn on error catching. I think it may have to do with some security MS has changed with some pathces latetly but I need to know how to work around it. Here is the code I uses:

Code:
Sub MapDrive(strDrive,strShare)
		
	On Error Resume Next
	
	For i = 0 to oDrives.Count - 1 Step 2
       
        If oDrives.Item(i+1) = strShare Then
           
           strStatus = strStatus & vbCRLF & strDrive & strShare & " already mapped."
           i = oDrives.count
           		
           		strMappedDrives = strMappedDrives & strDrive & " "
				ie.document.all.Msg2.InnerText = strMappedDrives

           Exit Sub
           
        Else
          
			WSHNetwork.MapNetworkDrive strDrive, strShare, "TRUE"

			If Err.Number Then

				Err.Clear
				WSHNetwork.RemoveNetworkDrive strDrive
		
				WScript.Sleep 2000 ' Allow drive to finish unmapping.
		
				WSHNetwork.MapNetworkDrive strDrive, strShare, "TRUE"
		
				If Err.Number <> 0 Then 'IF there is still an err then hold IE
					ie.document.all.holdit.checked = True
				Else
					IE.Document.all.holdit.checked = False	
				End If
				
			End If
		End If 
	Next
				strMappedDrives = strMappedDrives & strDrive & " "
				ie.document.all.Msg2.InnerText = strMappedDrives
				strStatus = strStatus & vbCRLF & strDrive & strShare & " " & Err.Description

 '  use to troubleshoot Err.Number
 '  MsgBox(Err.Number)
 '  MsgBox(Err.Description)
	

	
End Sub

Any idea's would be helpful. Thanks.
 
personally i would add some more logging information, perhaps to the eventlog or a logfile.
have it log every single step and you will see what is going on
 
The actual full script writes to a .txt file on the c:\ during boot. It is reporting successfull mapping. I am even having this trouble all of a sudden on my laptop. When I run this code in primal script I get no error codes, it shows that the drives map correctly but in windows they never do.
 
i would advise stripping the problem code out, in this case

WSHNetwork.MapNetworkDrive strDrive, strShare, "TRUE"

just have a script which has the WshNetwork declaration and the MapNetworkDrive method and see if you can successfully reproduce the problem. The circumstances under which you reproduce the problem should give you an indication of what the problem is

sorry i cant be of more help with a specific issue, i cant recall coming across something like this myself

 
Thanks will give that a try ... this is really baffling to me ...
 
i take it you have taken the On Error Resume Next out the top of the Sub routine?
this make the Sub bomb out as soon as it comes across a problem. ive posted it before but here you go use it if it helps you, this is how i map a drive

Public Function MapDrive(strDrvShare, blnPersistent, blnDisconnect)
On Error Resume Next
Dim blnDriveConnected
Dim blnAlreadyMapped
Dim strDrv
Dim strDrvLong
Dim strShare


blnAlreadyMapped = False
strDrv = Left(strDrvShare, 1)
strShare = Right(strDrvShare, Len(strDrvShare) - 2)
strDrvLong = strDrv & ":"
blnDriveConnected = FSO.DriveExists(strDrvLong)

If blnEnumDrives = False Then
Set enumDrives = WshNetwork.EnumNetworkDrives
blnEnumDrives = True
End If

If IsObject(enumDrives) Then
For i = 0 to enumDrives.Count -1
If enumDrives.Item(i) <> "" Then
If LCase(enumDrives.Item(i)) = LCase(strDrvLong) Then
'msgbox "found our drive already in use " & strDrvLong
If LCase(enumDrives.Item(i + 1)) = LCase(strShare) Then
'msgbox "found the share as well" & strShare
blnAlreadyMapped = True
End If
End If
End If
Next
End If

If blnAlreadyMapped = False Then
If FSO.FolderExists(strShare) Then
'msgbox "found that share " & strShare
Err.Clear
If blnDriveConnected = False Then
If blnDisconnect = "True" Then
'shouldnt need to disconnect here but just incase there is a persistant connection
'WshNetwork.RemoveNetworkDrive strDrvLong, True, True
WshNetwork.MapNetWorkDrive strDrvLong, strShare, blnPersistent
If Err.Number = 0 Then
MapDrive = 0
blnEnumDrives = False
Else
'Msgbox Err.Number
'shouldnt need to disconnect here but just incase there is a persistant, remembered connection
WshNetwork.RemoveNetworkDrive strDrvLong, True, True
WshNetwork.MapNetWorkDrive strDrvLong, strShare, blnPersistent
'msgbox "failed to map drive " & strDrvLong & strShare & " blPers " & blnPersistent
If Err.Number = 0 Then
MapDrive = 0
blnEnumDrives = False
Else
MapDrive = 4
End If
End If

Else
WshNetwork.MapNetWorkDrive strDrvLong, strShare, blnPersistent
If Err.Number = 0 Then
MapDrive = 0
blnEnumDrives = False
Else
'msgbox "failed to map drive " & strDrvLong & strShare & " blPers " & blnPersistent
MapDrive = 4
End If
End If
ElseIf blnDriveConnected = True And blnDisconnect = "False" Then
'msgbox "cannot map drive " & strDrvLong & " already in use and disconnect set to false."
MapDrive = 3
ElseIf blnDriveConnected = True And blnDisconnect = "True" Then
WshNetwork.RemoveNetworkDrive strDrvLong, True, True
WshNetwork.MapNetWorkDrive strDrvLong, strShare, blnPersistent
blnEnumDrives = False
If Err.Number = 0 Then
MapDrive = 0
Else
'msgbox "failed to map drive " & strDrvLong & strShare & " blPers " & blnPersistent
MapDrive = 2
End If
End If
Else
'msgbox "didnt find that share " & strShare & " " & strDrvLong
MapDrive = 1
End If
Else
MapDrive = 8 'already got it connected, might want to return 0
End If


End Function
 
I haven't had a chance to fully test this in production but WOW man this seems to map way faster than my code!!! bravo ... thanks ... is it because I was using a sub rather than a function?
 
mrmovie,

You are a life saver!!! Adjusted your function a tad to fit my logon script but it cured my problems company wide. Thank you very much.
 
thanks for the feedback creiners, im glad it helped.
just a quick note on the following lines, you may have already figures it out but...

If blnEnumDrives = False Then
Set enumDrives = WshNetwork.EnumNetworkDrives
blnEnumDrives = True
End If

These 2 variables

blnEnumDrives
enumDrives

need to be declared globally. the idea being you only want to grab the currently mapped network drives once when you start your script.
on the down side if y ou have 3 calls to the mapdrive function and 2 of them are for the same drive letter the enumDrives will not be upto date. i have not found it a problem and on the plus side it speeds things up.

regards,
von moyla
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top