Guest richard_s Posted August 12, 2009 Posted August 12, 2009 I'm in the process of writing a new logon script to replace several batch files but I'm having problems when it comes to running the script as nothing happens, no drives are mapped and no printer connections are created. I am basically a scripting noobie and could do with some help on this. On Error Resume Next '===TESTING ONLY=============================== Set oShell = CreateObject("WScript.Shell") Set wshNetwork = CreateObject("WScript.Network") Set objNetwork = CreateObject("WScript.Network") Set oPrinters = objNetwork.EnumPrinterConnections Set ADSysInfo = CreateObject("ADSystemInfo") Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName) strGroups = LCase(CurrentUser.DistinguishedName) Set CurrentComp = GetObject("LDAP://" & ADSysInfo.Computername) OrgUnit = Lcase(CurrentComp.distinguishedname) '==================================== ' User Grouping constants '==================================== Const DA = "ou=Admin" Const TEACHERS = "ou=Staff" Const PUPILS = "ou=Pupils" '========================================= ' PRINTERS = '========================================= Set WshNetwork = WScript.CreateObject("WScript.Network") PrinterPath = "\\savioursrv\HPLASERJETCOL3000" WshNetwork.AddWindowsPrinterConnection PrinterPath WshNetwork.SetDefaultPrinter var WshNetwork = WScript.CreateObject("WScript.Network"); var PrinterPath = "\\\\savioursrv\\HPLASERJETCOL3000"; WshNetwork.AddWindowsPrinterConnection(PrinterPath); WshNetwork.SetDefaultPrinter "ict01\HPLASERJETCOL3000"; '======================================== 'Domain Admins' drive shares '======================================== If InStr(strGroups, DA) Then wshNetwork.MapNetworkDrive "u:", "\\savioursrv\User$" wshNetwork.MapNetworkDrive "p:", "\\savioursrv\Public$" wshNetwork.MapNetworkDrive "t:", "\\savioursrv\SharedResources" wshNetwork.MapNetworkDrive "v:", "\\savioursrv\Photographs" '======================================== 'Teachers drive shares '======================================== ElseIf InStr(strGroups, TEACHERS) Then wshNetwork.MapNetworkDrive "u:", "\\savioursrv\User$\Pupils" wshNetwork.MapNetworkDrive "p:", "\\savioursrv\Public$" wshNetwork.MapNetworkDrive "t:", "\\savioursrv\SharedResources" wshNetwork.MapNetworkDrive "v:", "\\savioursrv\Photographs" '======================================== ' Pupils Year 3 Drive Maps '======================================== Elseif InStr(lcase(CurrentUser.Name),"3") Then wshNetwork.MapNetworkDrive "t:", "\\savioursrv\SharedResources\Year 3" wshNetwork.MapNetworkDrive "v:", "\\savioursrv\Photographs" '======================================== ' Pupils Year 4 Drive Maps '======================================== Elseif InStr(lcase(CurrentUser.Name),"4") Then wshNetwork.MapNetworkDrive "t:", "\\savioursrv\SharedResources\Year 4" wshNetwork.MapNetworkDrive "v:", "\\savioursrv\Photographs" '======================================== ' Pupils Year 5 Drive Maps '======================================== 'Elseif InStr(lcase(CurrentUser.Name),"5") Then wshNetwork.MapNetworkDrive "t:", "\\savioursrv\SharedResources\Year 5" wshNetwork.MapNetworkDrive "v:", "\\savioursrv\Photographs" '======================================== ' Pupils Year 6 Drive Maps '======================================== 'Elseif InStr(lcase(CurrentUser.Name),"6") Then wshNetwork.MapNetworkDrive "t:", "\\savioursrv\SharedResources\Year 6" wshNetwork.MapNetworkDrive "v:", "\\savioursrv\Photographs" End If
CyberNerd Posted August 12, 2009 Posted August 12, 2009 add a marker to see where it fails or if the script is getting run WScript.Echo(" some text!")
TheScarfedOne Posted August 12, 2009 Posted August 12, 2009 I'll second that. Also - get it to echo any variables to make sure it is returning what you think it is. Another hint, I use Notepad++ for writing our VBS scripts - as it will show the formatting for you. I will also be publishing a load of scripts as a "project", just need to clear it with James when I finally get chance to chat to him again since LG Conference.
Guest richard_s Posted August 12, 2009 Posted August 12, 2009 add a marker to see where it fails or if the script is getting run WScript.Echo(" some text!") I have just added this to the script and when I run it nothing happens.
TheScarfedOne Posted August 12, 2009 Posted August 12, 2009 Use the code at various points through the code (with the echo text telling you where in the code you are)... this will show where its getting to before falling over.
ChrisH Posted August 12, 2009 Posted August 12, 2009 Comment out On Error Resume Next It will then give you an error.
ChrisH Posted August 12, 2009 Posted August 12, 2009 Also this are doesn't look right var WshNetwork = WScript.CreateObject("WScript.Network"); var PrinterPath = "\\\\savioursrv\\HPLASERJETCOL3000"; WshNetwork.AddWindowsPrinterConnection(PrinterPath); WshNetwork.SetDefaultPrinter "ict01\HPLASERJETCOL3000"; Specifically the amount of back slashes and in some cases lack of eg on the SetDefaultPrinter. You do have to use extra back slashes when doing reg stuff sometimes but I dont think they are needed here. I am guessing it should look like this var WshNetwork = WScript.CreateObject("WScript.Network"); var PrinterPath = "\\savioursrv\HPLASERJETCOL3000"; WshNetwork.AddWindowsPrinterConnection(PrinterPath); WshNetwork.SetDefaultPrinter "\\ict01\HPLASERJETCOL3000";
TheScarfedOne Posted August 12, 2009 Posted August 12, 2009 (edited) Also... I would use Dim StrWhatever StrWhatever = Whatever Rather than using var and declaring value in the same place. Edited August 12, 2009 by TheScarfedOne Hit save too fast! Muppet :-(
Guest richard_s Posted August 12, 2009 Posted August 12, 2009 The problem seems to lie with the group specfic shares as I changed the script so that wshNetwork.MapNetworkDrive "v:", "\\savioursrv\Photographs" mapping was done separtley to the others and it is the only share that is mapped at logon.
ChrisH Posted August 12, 2009 Posted August 12, 2009 So you need to check if the group check is working then? Try this If InStr(strGroups, DA) Then Wscipt.echo "User has passed the admins check" wshNetwork.MapNetworkDrive "u:", "\\savioursrv\User$" wshNetwork.MapNetworkDrive "p:", "\\savioursrv\Public$" wshNetwork.MapNetworkDrive "t:", "\\savioursrv\SharedResources" wshNetwork.MapNetworkDrive "v:", "\\savioursrv\Photographs" '======================================== 'Teachers drive shares '======================================== ElseIf InStr(strGroups, TEACHERS) Then Wscript.Echo "This user is a teacher" wshNetwork.MapNetworkDrive "u:", "\\savioursrv\User$\Pupils" wshNetwork.MapNetworkDrive "p:", "\\savioursrv\Public$" wshNetwork.MapNetworkDrive "t:", "\\savioursrv\SharedResources" wshNetwork.MapNetworkDrive "v:", "\\savioursrv\Photographs" Try an admin and a teacher account. If you dont get a popup then your group checking code isn't working.
altecsole Posted August 12, 2009 Posted August 12, 2009 Where are you getting the value of strGroups from? Do a wscript.echo strGroups to check the value. Also, it's good practise to add Option Explicit to the top of your script. That forces you to declare all varables before you use them.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now