Only part of Logon script works on Windows 2003 Domain


  Well I am having an issue with a logon script that only does part of what it should do. The script I have pasted below is the one in question. This script reads from a SQL database the workstation name and drives/printers to map and then does its thing. The part of the script that maps my printers works fine but the part that maps the drives does not work. It is at line 107 inside of the Function MapDrive (DriveLetter, UNCPath) and this line "WshNetwork.MapNetworkDrive DriveLetter,UNCPath" is where it gets the error shown at the bottom of this message.    
If you go to the bottom of this message you will see where I have queried a few of the variables and determined that they are correct, but it gives the error Network Path not found. And I have verified that all of the drive mappings are correct... I can copy right from the database the share name and paste it in to a Start-Run command and it brings up the share just fine. The printer function works fine. I can read and write inside the shares with no problem. This script also works on another site where I work with no issues. Any ideas? Thanks,


'MapWorkStationDrivesAndPrinters.vbs - Script to Map Network (NOT LOCAL) Drives and Printers for a Workstation
'                              - The Drive and Printer Mappings Come from the LCPC_WSDriveAndPrinterMaps
'                                table in the AppsMain database on the ISSQL2 server
'* Create network objects for later reference
Dim WshNetwork
Dim ObjSysInfo
Dim ClientName
Dim wsName
Dim mPrinters
Dim mDrives

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objSysInfo = CreateObject("ADSystemInfo")

'Open connection to LCPC created tables store on the ISSQL2 sql server
Dim conn, rs,SQLText
 Set conn=CreateObject("ADODB.Connection")
With conn
    If .State = 0 Then
            .Provider = "SQLOLEDB"
            .ConnectionString = "User ID=WSmap;" & _
                                "Password='';" & _
                                "Data Source=ISSQL2;" & _
                                "Initial Catalog=AppsMain"
            .ConnectionTimeout = 20
    End If
End With
'Find the drive and printer mappings that have been assign to this computer name in the table then MapDrive
'LCPC_WSDriveAndPrinterMaps Row Example:
'WSMapID   WSName      DriveLetter  ShareName                DefaultPrinterFlg
'   1      W4657           O       \\ISSQL2\Medinfo                0
'   2        *                 S           \\ISTRM2\Users                0
'   3      W4657         (NULL)    \\SomePrinterShareName         1
'   4      W4657           (NULL)    \\AnotherPrinterShareName      0
'Notice the * for WSName.  This is a Global setting whereby all workstations that run this script will get this
'                        mapping; however, the global setting will be overwritten if the workstation
'                        has an explicit entry for a drive letter
 Set rs=CreateObject("ADODB.Recordset")
 wsName = WshNetwork.ComputerName

 SQLText = "Select * from LCPC_WSDriveAndPrinterMaps  where WSName = '" & wsName & "'"
 rs.Open SQLText, Conn, 0,1
 On Error Resume Next
 If err.number = 3021 Then WScript.Quit
Set oDrives = WshNetwork.EnumNetworkDrives
      mDrives = oDrives.Count - 1
          For i = 0 to mDrives Step 2
                If oDrives.Item(i) <> "U:" Then
                      WshNetwork.RemoveNetworkDrive oDrives.Item(i), True, True
                End If
Set oPrints = WshNetwork.EnumPrinterConnections
          mPrinters = oPrints.Count - 1
      For i = 0 to oPrints.Count - 1 Step 2
                WshNetwork.RemovePrinterConnection oPrints.Item(i+1)
If Err.Number<>0 Then Err.Clear


 SQLText = "Select * from LCPC_WSDriveAndPrinterMaps  where WSName = '" & wsName & "'" & " Or WSName = '*' Order By WSName"
 rs.Open SQLText, Conn, 0,1
 On Error Resume Next
 Do While not rs.EOF
      If IsNull(rs("DriveLetter")) Then
            MapPrinter rs("ShareName")
            If rs("DefaultPrinterFlg") Then WshNetwork.SetDefaultPrinter rs("ShareName")                  
             MapDrive rs("DriveLetter") & ":" ,rs("ShareName")
      End If


Set rs=Nothing
Set Conn=Nothing

'* Functions

Function MapDrive (DriveLetter, UNCPath)
    On Error Resume Next
    WshNetwork.RemoveNetworkDrive DriveLetter
    WshNetwork.MapNetworkDrive DriveLetter,UNCPath
    If Err.Number <> 0 Then
        PrintMessageBox "Error mapping " & DriveLetter & " to path " & UNCPath
    End If
End Function

Function MapPrinter (UNCPath)
    WshNetwork.AddWindowsPrinterConnection UNCPath
    If Err.Number <> 0 Then
        PrintMessageBox "Error mapping printer " & UNCPath
    End If
Exit Function
BailonFailure err.number, err.description
End Function

'* Error Output to User
Sub BailOnFailure(ErrNum, ErrText)
    strText = "Please report the following to your department's system administrator:" & vbCR & ErrText & vbCR & "Error 0x" & Hex(ErrNum)
    MsgBox strText, vbInformation, "Logon Script Error"
End Sub

Sub PrintMessageBox(ErrText)
Exit Sub
    strText = "Please report the following to your department's system administrator:" & vbCR & ErrText
    MsgBox strText, vbInformation, "Logon Script Error"
End Sub

************  Results while in Debug mode **********

The network path was not found.



Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The script below works for me when I replace \\server\share with a valid share.  It's just the portion of your script that maps the drive.

Use it to see if \\ISSQL2\MEDINFO is there - also check to see if this isn't a hidden share MEDINFO$.


Dim WshNetwork
Dim DriveLetter
Dim UNCPath

UNCPath = "\\server\share"

Set WshNetwork = WScript.CreateObject("WScript.Network")

WshNetwork.MapNetworkDrive DriveLetter, UNCPath



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SOMCEEAuthor Commented:

 DUH!!! I seen my mistake as soon as I looked at your code... I thought I had changed this and tried it once before but evidently NOT!! The problem was I had in the database "\\server\share\" it should be "\\server\share" NO ending backslash!! Thanks for helping by just letting me see it on paper... feel really stupid!! Just tried it and it works like a champ!!
No problem!  Sometimes, when you work at something long enough you look right past the obvious.  An extra set of eyes is always welcome.

Glad to help!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2003

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.