locked
Map network drive fails but errorcode is 0 RRS feed

  • Question

  • hi,

    i'm experiencing a strange issue with a logon script executed via GP at user logon.

    The script (it worked for years) tries to map some network drivers.

    Since a couple of week the script returns no error but no drives are mapped.

    i've tried to debug writing down some info in a log file.

    Here below is the function called to map the drive.

    the strange issue is that executing the script when from desktop shortcut it works fine.

    Can anyone help me to fix it ?

    Thanks in advance 

    Function MapDrive(strDrive, strShare, strRename)
    
    Dim objDrive
    Dim mDrive
    
    On Error Resume Next
    If objFSO.DriveExists(strDrive) Then
    	Set objDrive = objFSO.GetDrive(strDrive)
    	If Err.Number <> 0 Then
    		MsgBox "GetDrive - Err.Number: " & Err.Number
    		MsgBox "GetDrive - Err.Description: " & Err.Description
    		On Error GoTo 0
    		MapDrive = False
    		Exit Function
    	End If
    	If CBool(objDrive.DriveType = 3) Then
    	    objNetwork.RemoveNetworkDrive strDrive, True, True
    	Else
        	MapDrive = False
    	    Exit Function
    	End If
    	Set objDrive = Nothing
    End If
    objNetwork.MapNetworkDrive strDrive, strShare
    
    If Err.Number = 0 Then
    	MapDrive = True
    	mDrive = strDrive & "\"
    	objShell.NameSpace(mDrive).Self.Name = strRename
    	Set mDrive = Nothing
    Else
    	MsgBox "MapNetworkDrive - Err.Number: " & Err.Number
    	MsgBox "MapNetworkDrive - Err.Description: " & Err.Description
    	Err.Clear
    	MapDrive = False
    End If
    On Error GoTo 0
       
    End Function



    Walimay


    • Edited by Walimay Wednesday, September 13, 2017 8:54 AM title editing
    • Moved by Bill_Stewart Tuesday, November 7, 2017 9:40 PM This is not "fix/debug/rewrite my script for me" forum
    Wednesday, September 13, 2017 8:53 AM

All replies

  • The script will never return any errors because your error handling is not correct and is turned off.  You will also not get the message box if the GP settings do not run the script correctly.

    Use GP to map drives.  We haven't used logon scripts since W2K.

    Also note that your function is never being called so nothing will happen anyway.


    \_(ツ)_/


    • Edited by jrv Wednesday, September 13, 2017 9:04 AM
    Wednesday, September 13, 2017 9:04 AM
  • thanks for you reply.

    even if I modify the script with error handling I get the same result.

    the code below is a portion of the whole script.

    the function reported here below is executed, and I get the log (see below) but the user don't see any mapped drive at logon.

    Function MapDrive(strDrive, strShare, strRename)
    
    Dim objDrive
    Dim mDrive
    
    On Error goto 0
    err.clear
    If objFSO.DriveExists(strDrive) Then
    	Set objDrive = objFSO.GetDrive(strDrive)
    	If Err.Number <> 0 Then
    		MsgBox "GetDrive - Err.Number: " & Err.Number
    		MsgBox "GetDrive - Err.Description: " & Err.Description
    		On Error GoTo 0
    		MapDrive = False
    		Exit Function
    	End If
    	If CBool(objDrive.DriveType = 3) Then
    	    objNetwork.RemoveNetworkDrive strDrive, True, True
    	Else
        	MapDrive = False
    	    Exit Function
    	End If
    	Set objDrive = Nothing
    End If
    err.clear
    objNetwork.MapNetworkDrive strDrive, strShare
    
    If Err.Number = 0 Then
    	logfile.writeline("mappato disco " & strdrive & " su " & strshare & " Err.Number: " & Err.Number)
    	MapDrive = True
    	mDrive = strDrive & "\"
    	'objShell.NameSpace(mDrive).Self.Name = strRename
    	Set mDrive = Nothing
    Else
    	MsgBox "MapNetworkDrive - Err.Number: " & Err.Number
    	MsgBox "MapNetworkDrive - Err.Description: " & Err.Description
    	logfile.writeline("errore mappatura disco " & strdrive & " " & err.description)
    	Err.Clear
    	MapDrive = False
    End If
    On Error GoTo 0
       
    End Function

    log from the script:

    ************** Avvio Logon Script - 13/09/2017 10:04:19 *****
    
      Dominio ........... MyDomain
      Logon Server ...... DC2.MyDomain.LOCAL
      Logon Script ...... login_disk.vbs (1.50 - debug)
      Data .............. mercoledì 13 settembre 2017
      Ora ............... 10:04
      Workstation ....... WorkStationName
      User ID ........... Username
      User Name ......... Surname FirstName
    mappato disco Z: su \\MyDomain.local\italy\Users\username Err.Number: 0
    mappato disco W: su \\MyDomain.local\italy\ProgettiAziendali\Condivisione.con.Spagna Err.Number: 0
    mappato disco G: su \\MyDomain.local\italy\monitoraggio Err.Number: 0
    mappato disco K: su \\MyDomain.local\italy\DirezioneGestioneMerci\distributori Err.Number: 0
    mappato disco L: su \\MyDomain.local\italy\DistribuzioneLogistica Err.Number: 0
    mappato disco Q: su \\MyDomain.local\Italy\DirezioneProdotto\Acquisti Err.Number: 0
    mappato disco o: su \\MyDomain.local\italy\DirezioneGestioneMerci\4CAT Err.Number: 0
    mappato disco S: su \\MyDomain.local\italy\SAPKEYUSER Err.Number: 0



    Walimay

    Wednesday, September 13, 2017 9:30 AM
  • As I tried to tell you, the function can exit with success even if it has failed.  The error checking doesn't work as you expect.  If the shell calls fail the error will be ignored because it is not being checked.  You must not use MsgBox in a logon script and you must check for every possible error condition when you use "On Error Resume Next".


    \_(ツ)_/

    Wednesday, September 13, 2017 9:36 AM