+ Post New Thread
Results 1 to 11 of 11
Scripts Thread, New logonscript not working in Coding and Web Development; I'm in the process of writing a new logon script to replace several batch files but I'm having problems when ...
  1. #1
    richard_s
    Guest

    New logonscript not working

    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.

    Code:
    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

  2. IDG Tech News

  3. #2


    Join Date
    Jan 2006
    Posts
    6,457
    Thank Post
    324
    Thanked 740 Times in 557 Posts
    Rep Power
    201
    add a marker to see where it fails or if the script is getting run
    Code:
    WScript.Echo(" some text!")

  4. #3
    TheScarfedOne's Avatar
    Join Date
    Apr 2007
    Location
    Plymouth, Devon
    Posts
    610
    Blog Entries
    65
    Thank Post
    196
    Thanked 65 Times in 58 Posts
    Rep Power
    52
    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.

  5. #4
    richard_s
    Guest
    Quote Originally Posted by CyberNerd View Post
    add a marker to see where it fails or if the script is getting run
    Code:
    WScript.Echo(" some text!")
    I have just added this to the script and when I run it nothing happens.

  6. #5
    TheScarfedOne's Avatar
    Join Date
    Apr 2007
    Location
    Plymouth, Devon
    Posts
    610
    Blog Entries
    65
    Thank Post
    196
    Thanked 65 Times in 58 Posts
    Rep Power
    52
    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.

  7. #6
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,810
    Thank Post
    89
    Thanked 212 Times in 195 Posts
    Rep Power
    83
    Comment out

    Code:
    On Error Resume Next
    It will then give you an error.

  8. #7
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,810
    Thank Post
    89
    Thanked 212 Times in 195 Posts
    Rep Power
    83
    Also this are doesn't look right

    Code:
    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

    Code:
    var WshNetwork = WScript.CreateObject("WScript.Network");
    var PrinterPath = "\\savioursrv\HPLASERJETCOL3000";
    WshNetwork.AddWindowsPrinterConnection(PrinterPath);
    WshNetwork.SetDefaultPrinter "\\ict01\HPLASERJETCOL3000";

  9. #8
    TheScarfedOne's Avatar
    Join Date
    Apr 2007
    Location
    Plymouth, Devon
    Posts
    610
    Blog Entries
    65
    Thank Post
    196
    Thanked 65 Times in 58 Posts
    Rep Power
    52
    Also... I would use

    Code:
    Dim StrWhatever
    
    StrWhatever = Whatever
    Rather than using var and declaring value in the same place.
    Last edited by TheScarfedOne; 12th August 2009 at 12:53 PM. Reason: Hit save too fast! Muppet :-(

  10. #9
    richard_s
    Guest
    The problem seems to lie with the group specfic shares as I changed the script so that

    Code:
    wshNetwork.MapNetworkDrive "v:", "\\savioursrv\Photographs"
    mapping was done separtley to the others and it is the only share that is mapped at logon.

  11. #10
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,810
    Thank Post
    89
    Thanked 212 Times in 195 Posts
    Rep Power
    83
    So you need to check if the group check is working then?

    Try this

    Code:
    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.

  12. #11
    altecsole's Avatar
    Join Date
    Jun 2005
    Location
    Morecambe, Lancashire, UK.
    Posts
    281
    Thank Post
    37
    Thanked 33 Times in 26 Posts
    Rep Power
    18
    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.

SHARE:
+ Post New Thread

Similar Threads

  1. Keyboard not working
    By imiddleton25 in forum Windows
    Replies: 5
    Last Post: 2nd March 2009, 05:44 PM
  2. strange nic lights working/not working
    By browolf in forum Networks
    Replies: 13
    Last Post: 15th December 2008, 02:50 PM
  3. It's working! At last
    By localzuk in forum General Chat
    Replies: 4
    Last Post: 10th September 2008, 06:13 PM
  4. No More working!!!!!
    By Scotmk in forum General Chat
    Replies: 2
    Last Post: 23rd July 2008, 12:04 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •