• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 954
  • Last Modified:

Only part of Logon script works on Windows 2003 Domain

Hello,

  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,

Kerry



'
'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
            .Open
    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
 rs.movefirst
 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
          Next
Set oPrints = WshNetwork.EnumPrinterConnections
          mPrinters = oPrints.Count - 1
      For i = 0 to oPrints.Count - 1 Step 2
                WshNetwork.RemovePrinterConnection oPrints.Item(i+1)
          Next
If Err.Number<>0 Then Err.Clear

 
 rs.Close

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

 rs.Close


Set rs=Nothing
Conn.Close
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
        Err.Clear
    End If
End Function


Function MapPrinter (UNCPath)
    WshNetwork.AddWindowsPrinterConnection UNCPath
    If Err.Number <> 0 Then
        PrintMessageBox "Error mapping printer " & UNCPath
        Err.Clear
    End If
Exit Function
MapFail:
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"
    WScript.Quit
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"
    Err.Clear
End Sub



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

?err.description
The network path was not found.

?err.number
-2147024843

?UNCPath
\\ISSQL2\MEDINFO\

?DriveLetter
M:
0
SOMCEE
Asked:
SOMCEE
  • 2
1 Solution
 
Netman66Commented:
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


DriveLetter="T:"
UNCPath = "\\server\share"

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

WshNetwork.MapNetworkDrive DriveLetter, UNCPath

---------

Advise.
0
 
SOMCEEAuthor Commented:
netman66


 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!!
0
 
Netman66Commented:
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!

NM
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now