+ 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. #2


    Join Date
    Jan 2006
    Posts
    8,202
    Thank Post
    442
    Thanked 1,033 Times in 813 Posts
    Rep Power
    341
    add a marker to see where it fails or if the script is getting run
    Code:
    WScript.Echo(" some text!")

  3. #3
    TheScarfedOne's Avatar
    Join Date
    Apr 2007
    Location
    Plymouth, Devon
    Posts
    1,123
    Thank Post
    767
    Thanked 176 Times in 159 Posts
    Blog Entries
    78
    Rep Power
    86
    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.

  4. #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.

  5. #5
    TheScarfedOne's Avatar
    Join Date
    Apr 2007
    Location
    Plymouth, Devon
    Posts
    1,123
    Thank Post
    767
    Thanked 176 Times in 159 Posts
    Blog Entries
    78
    Rep Power
    86
    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.

  6. #6
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,007
    Thank Post
    124
    Thanked 286 Times in 263 Posts
    Rep Power
    109
    Comment out

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

  7. #7
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,007
    Thank Post
    124
    Thanked 286 Times in 263 Posts
    Rep Power
    109
    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";

  8. #8
    TheScarfedOne's Avatar
    Join Date
    Apr 2007
    Location
    Plymouth, Devon
    Posts
    1,123
    Thank Post
    767
    Thanked 176 Times in 159 Posts
    Blog Entries
    78
    Rep Power
    86
    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 01:53 PM. Reason: Hit save too fast! Muppet :-(

  9. #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.

  10. #10
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,007
    Thank Post
    124
    Thanked 286 Times in 263 Posts
    Rep Power
    109
    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.

  11. #11
    altecsole's Avatar
    Join Date
    Jun 2005
    Location
    Whittington, Lancashire
    Posts
    286
    Thank Post
    40
    Thanked 37 Times in 27 Posts
    Rep Power
    26
    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 Wireless 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, 07:13 PM
  4. No More working!!!!!
    By Scotmk in forum General Chat
    Replies: 2
    Last Post: 23rd July 2008, 01: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
  •