SOMCEE
asked on
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.MapNetworkDriv e 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
'
'MapWorkStationDrivesAndPr inters.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("WScr ipt.Networ k")
Set objSysInfo = CreateObject("ADSystemInfo ")
'========================= =======
'Open connection to LCPC created tables store on the ISSQL2 sql server
Dim conn, rs,SQLText
Set conn=CreateObject("ADODB.C onnection" )
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_WSDriveAndPrinterMap s 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.Rec ordset")
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.EnumNetworkDriv es
mDrives = oDrives.Count - 1
For i = 0 to mDrives Step 2
If oDrives.Item(i) <> "U:" Then
WshNetwork.RemoveNetworkDr ive oDrives.Item(i), True, True
End If
Next
Set oPrints = WshNetwork.EnumPrinterConn ections
mPrinters = oPrints.Count - 1
For i = 0 to oPrints.Count - 1 Step 2
WshNetwork.RemovePrinterCo nnection 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.SetDefaultPrint er 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.RemoveNetworkDr ive 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.AddWindowsPrint erConnecti on 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:
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.MapNetworkDriv
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
'
'MapWorkStationDrivesAndPr
' - 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("WScr
Set objSysInfo = CreateObject("ADSystemInfo
'=========================
'Open connection to LCPC created tables store on the ISSQL2 sql server
Dim conn, rs,SQLText
Set conn=CreateObject("ADODB.C
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_WSDriveAndPrinterMap
'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.Rec
wsName = WshNetwork.ComputerName
SQLText = "Select * from LCPC_WSDriveAndPrinterMaps
rs.Open SQLText, Conn, 0,1
On Error Resume Next
rs.movefirst
If err.number = 3021 Then WScript.Quit
Set oDrives = WshNetwork.EnumNetworkDriv
mDrives = oDrives.Count - 1
For i = 0 to mDrives Step 2
If oDrives.Item(i) <> "U:" Then
WshNetwork.RemoveNetworkDr
End If
Next
Set oPrints = WshNetwork.EnumPrinterConn
mPrinters = oPrints.Count - 1
For i = 0 to oPrints.Count - 1 Step 2
WshNetwork.RemovePrinterCo
Next
If Err.Number<>0 Then Err.Clear
rs.Close
SQLText = "Select * from LCPC_WSDriveAndPrinterMaps
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.SetDefaultPrint
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.RemoveNetworkDr
WshNetwork.MapNetworkDrive
If Err.Number <> 0 Then
PrintMessageBox "Error mapping " & DriveLetter & " to path " & UNCPath
Err.Clear
End If
End Function
Function MapPrinter (UNCPath)
WshNetwork.AddWindowsPrint
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:
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
Glad to help!
NM
ASKER
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!!