+ Post New Thread
Results 1 to 9 of 9
Scripts Thread, Log on Scripts in Coding and Web Development; Can anyone send me an example of a log on script that connects user's drives, adds a few printers and ...
  1. #1
    button_ripple's Avatar
    Join Date
    Dec 2007
    Location
    Luton
    Posts
    346
    Thank Post
    93
    Thanked 20 Times in 18 Posts
    Rep Power
    13

    Log on Scripts

    Can anyone send me an example of a log on script that connects user's drives, adds a few printers and sets a default printer?

    Thankyou!

  2. IDG Tech News

  3. #2

    mattx's Avatar
    Join Date
    Jan 2007
    Posts
    8,472
    Thank Post
    889
    Thanked 890 Times in 532 Posts
    Rep Power
    596
    Quote Originally Posted by button_ripple View Post
    Can anyone send me an example of a log on script that connects user's drives, adds a few printers and sets a default printer?

    Thankyou!
    Logon file - [ .BAT ]

    Code:
    net time \\stjohns01 /set /yes
    
    if %OS%==Windows_NT goto NTWKS
    
    net use n: /home
    net use p: \\stjohns01\apps
    net use g: \\stjohns01\cse$
    net use v: \\stjohns01\cdcache
    g:
    cd profiles\kix32
    kix32 students.txt
    c:
    net use g: /d /y
    net use f: \\stjohns01\cse$
    goto end
    
    :NTWKS
    
    net use f: \\stjohns01\cse$ /PERSISTENT:NO
    net use P: \\stjohns01\apps /PERSISTENT:NO
    net use V: \\stjohns01\cdcache /PERSISTENT:NO
    net use r: \\stjohns01\resource$ /PERSISTENT:NO
    net use s: "\\stjohns01\Shared Areas" /PERSISTENT:NO
    net use w: \\stjohns01\work /PERSISTENT:NO
    
    gpupdate
    :END
    Printer [ with default ] in VBS

    Code:
    Set WshNetwork = CreateObject("WScript.Network")
    
    On Error Resume Next
    Set oPrinters = WshNetwork.EnumPrinterConnections
            For i = 1 to oPrinters.Count - 1 Step 2
                  WshNetwork.RemovePrinterConnection oPrinters.Item(i)
            Next
    
    Set WshNetwork = CreateObject("WScript.Network")
    WshNetwork.AddWindowsPrinterConnection "\\STJohns01\ICT_LASER"
    WshNetwork.AddWindowsPrinterConnection "\\STJohns01\Brother Laser ICT"
    
    WshNetwork.SetDefaultPrinter "\\STJohns01\Brother Laser ICT"

  4. Thanks to mattx from:

    button_ripple (11th March 2008)

  5. #3
    button_ripple's Avatar
    Join Date
    Dec 2007
    Location
    Luton
    Posts
    346
    Thank Post
    93
    Thanked 20 Times in 18 Posts
    Rep Power
    13
    how do i get them 2 scripts to run at the same time/work together?

    Ideally i want the network drives and printers to be set-up at log on

  6. #4

    mattx's Avatar
    Join Date
    Jan 2007
    Posts
    8,472
    Thank Post
    889
    Thanked 890 Times in 532 Posts
    Rep Power
    596
    Quote Originally Posted by button_ripple View Post
    how do i get them 2 scripts to run at the same time/work together?

    Ideally i want the network drives and printers to be set-up at log on
    You could call the VBS printer script from the .BAT file - or use some VBS to map drives instead of using the net use command !! The only reason I have it like that is because thats how the school implemented it before I joined. I have only made very minor changes to the logon process as it works very well.

  7. #5
    cromertech's Avatar
    Join Date
    Dec 2007
    Location
    Cromer by the coast
    Posts
    605
    Thank Post
    118
    Thanked 90 Times in 84 Posts
    Rep Power
    34
    The logon scripts were in short awful when i first came here. I now have one script that works with the active directory structure. Have a look at http://www.primalscript.com/Free_Tools/index.asp and the logon script generator. With this you can map drives to specific user groups and allocate printers the same way if you wish, however server 2003 R2 lets you deploy printers to specific active directory groups. This means that an it room can have a single printer assigned to it, particularly handy for the students that are able to log on to any computer in any room

  8. #6

    Join Date
    Jul 2007
    Location
    Devon
    Posts
    233
    Thank Post
    8
    Thanked 9 Times in 8 Posts
    Rep Power
    11
    This would be our incomplete, but working one, I left the rest out since it's not working 100%, reads a few files and does some things which are student specific just for fun etc.

    (Don't ask why I didn't just enumerate the drives, because I don't know )

    Code:
    '--------------------------------------
    ' South Dartmoor Community College
    '--------------------------------------
    ' Script Name: logon.vbs
    '  Created On: Wednesday, December 5, 2007
    '  Created By: Philip Widdowson
    ' Last Edited: 
    '   Edited By: 
    '--------------------------------------
    
    	On Error Resume Next
    
    '--------------------------------------
    ' Set up Variables and Create Objects
    '--------------------------------------
    
    	Dim oNet, oFSO, oWSH, ADSysInfo, CurrentUser, oTF
    	Dim FPath, GPath, KPath, MPath, NPath, OPath, PPath, SPath, UPath
    	Dim PE
    	Dim Message, PathToConfig, WallPaperPath, ActiveDesktopPath
    
    	Const TitleBar = "South Dartmoor Community College"
    	Const crlf = chr (13) & chr (10)
    
    	Set oNet = CreateObject("WScript.Network")
    	Set oFSO = CreateObject("Scripting.FileSystemObject")
    	Set oWSH = CreateObject("WScript.Shell")
    	Set ADSysInfo = CreateObject("ADSystemInfo")
    	Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
    
    	FPath = "\\simsserver\admin"
    	MPath = "\\nx1950-stu\class-files"
    	MPathE = "\\nx1950-stu\class-files\Exams\"
    	NPath = "\\nx1950-adm\staff-pers\" & oNet.UserName
    	OPath = "\\nx1950-stu\students\intake" & Left( oNet.Username, 2 ) & "\" oNet.UserName
    	PPath = "\\nx1950-adm\apps-share"
    	SPath = "\\nx1950-adm\staff-shared"
    	UPath = "\\nx1950-stu\students"
     
    '--------------------------------------
    ' Random Message
    '--------------------------------------
    
    	Message = "Welcome to " & oNet.UserDomain & ". Please wait while you are logged on."
    	oWSH.Popup Message, 2, TitleBar
    
    '--------------------------------------
    ' Do Student or Staff specific things
    '--------------------------------------
    
    	If oFSO.DriveExists("F:") Then oNet.RemoveNetworkDrive "F:", True, True
    	If oFSO.DriveExists("G:") Then oNet.RemoveNetworkDrive "G:", True, True
    	If oFSO.DriveExists("K:") Then oNet.RemoveNetworkDrive "K:", True, True
    	If oFSO.DriveExists("M:") Then oNet.RemoveNetworkDrive "M:", True, True
    	If oFSO.DriveExists("N:") Then oNet.RemoveNetworkDrive "N:", True, True
    	If oFSO.DriveExists("O:") Then oNet.RemoveNetworkDrive "O:", True, True
    	If oFSO.DriveExists("P:") Then oNet.RemoveNetworkDrive "P:", True, True
    	If oFSO.DriveExists("S:") Then oNet.RemoveNetworkDrive "S:", True, True
    	If oFSO.DriveExists("U:") Then oNet.RemoveNetworkDrive "U:", True, True
    
    	If LCase( Left( oNet.UserName, 1 ) ) = "0" Then
    
    		If Not oFSO.DriveExists("M:") Then oNet.MapNetworkDrive "M:", MPath
    		If Not oFSO.DriveExists("O:") Then oNet.MapNetworkDrive "O:", OPath
    		If Not oFSO.DriveExists("P:") Then oNet.MapNetworkDrive "P:", PPath
    
    	ElseIf LCase( Left( oNet.UserName, 4 ) ) = "exam" Then
    		
    		If Not oFSO.DriveExists("M:") Then oNet.MapNetworkDrive "M:", MPathE
    		If Not oFSO.DriveExists("O:") Then oNet.MapNetworkDrive "O:", OPath
    
    	Else
    
    		If Not oFSO.DriveExists("F:") Then oNet.MapNetworkDrive "F:", FPath, False
    		If Not oFSO.DriveExists("M:") Then oNet.MapNetworkDrive "M:", MPath, False
    		If Not oFSO.DriveExists("N:") Then oNet.MapNetworkDrive "N:", NPath, False
    		If Not oFSO.DriveExists("P:") Then oNet.MapNetworkDrive "P:", PPath, False
    		If Not oFSO.DriveExists("S:") Then oNet.MapNetworkDrive "S:", SPath, False
    		If Not oFSO.DriveExists("U:") Then oNet.MapNetworkDrive "U:", UPath, False
    
    	End If
    
    '--------------------------------------
    ' Local NAS Mapping
    '--------------------------------------
    
    	If LCase( Left( oNet.ComputerName, 2) ) = "pe" Then 
    
    		If InStr( StrGroups, PE ) Then oNet.MapNetworkDrive "G:", "\\10.3.47.220\pe"
    
    	End If
    We deploy our printers using R2 PMC which is rather useful for this.

  9. #7
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,430
    Thank Post
    79
    Thanked 90 Times in 86 Posts
    Rep Power
    32
    In this thread djones is trying to do what you want.

    Printer and Mapped Drive Script

  10. #8

    Join Date
    Oct 2007
    Location
    Cambridgeshire, UK
    Posts
    274
    Thank Post
    52
    Thanked 20 Times in 18 Posts
    Rep Power
    13
    Yeah, and everything seems to work apart from the drive renaming! The same code works in another script I use so it is very frustrating. Haven't had the chance to continue testing this week though.

    Dave

  11. #9
    Gibbo's Avatar
    Join Date
    Feb 2008
    Location
    Cheshire
    Posts
    1,895
    Thank Post
    143
    Thanked 294 Times in 196 Posts
    Rep Power
    78
    My school uses a KIX script to do the job. It seems to work ok so I've not felt the need to change it.

    I've trimmed this one down to just show printers and mapped drives.

    Code:
    ;  KiXtart logon script
    ;   Copyright (C) 2001 Ruud van Velsen.
    ;   All rights reserved.
    
    CLS
    
    small
    Color b+/b
    BOX (0,0,30,79,GRID)            ; 'background grid'
    Color b/n
    BOX (5,5,25,74,Å)              ; 'shadow' of the box
    Color g+/b
    BOX (4,4,24,73,FULL)
    
    Color r+/b
    at (2,8)   "Hello,"
    at (2,16) @fullname
    Color y+/b
    at (3,8)  "DO NOT CLOSE THIS WINDOW!!!"
    
    Color w+/b
    AT (7,25) "Userid       : "    ; display some text strings
    AT (8,25) "Full name    : "
    AT (9,25) "Privilege    : "
    AT (10,25) "Workstation  : "
    AT (11,25) "Domain       : "
    AT (12,25) "Logon Server : "
    
    Color y+/b
    AT (7,40) @userid              ; ...and some macro's
    AT (8,40) @fullname
    AT (9,40) @primarygroup
    AT (10,40) @wksta
    AT (11,40) @domain
    AT (12,40) @lserver
    
    Dim $RoomName
    If InStr(@WKSTA, "-") > 0
    	$RoomName=Left(@WKSTA, (InStr(@WKSTA, "-")-1))
    EndIf
    
    At (13,25) "Adding Distrib and Drop folders for All Users"
    use j: "\\share-server\distrib" 
    use k: "\\share-server\drop"
    
    ;Make the boardworks folder available to staff as a mapped drive
    if InGroup("Staff")
     At (13,25) "Adding Boardworks folder for staff"
     use l: "\\share-server\Boardworks"
    endif
    
    ; Deletes all mapped printers from machine
    $junk = DelTree("HKEY_CURRENT_USER\Printers\Connections")
    
    AT (14,25) "Adding IT1 Printer"
    $Junk=AddPrinterConnection ("\\print-server\PRINTIT1")
    
    AT (15,25) "Adding IT2 Printer"
    $Junk=AddPrinterConnection ("\\print-server\PRINTIT2")
    
    if InGroup("Staff")
     AT (20,25) "Adding Staff Printer"
     $Junk=AddPrinterConnection ("\\print-server\PRINTLAP")
    
    ; Find the room that the printer is in and set the default printer accordingly
    
    If $RoomName = "IT1"
     $Junk = SetDefaultPrinter("\\print-server\PRINTIT1")
     AT (22,25) "Setting IT1 Printer as default"
    EndIf
    
    If $RoomName = "IT2"
     $Junk = SetDefaultPrinter("\\print-server\PRINTIT2")
     AT (22,25) "Setting IT2 Printer as default"
    EndIf
    
    sleep 0.5
    
    exit

SHARE:
+ Post New Thread

Similar Threads

  1. Help running scripts within scripts
    By SimpleSi in forum *nix
    Replies: 7
    Last Post: 7th March 2008, 10:23 AM
  2. login scripts
    By palmer_eldritch in forum Mac
    Replies: 1
    Last Post: 6th March 2008, 11:47 AM
  3. What do you use for your logon scripts.
    By Kyle in forum How do you do....it?
    Replies: 17
    Last Post: 13th October 2006, 07:54 AM
  4. Scripts, Scripts, Scripts
    By wesleyw in forum Windows
    Replies: 18
    Last Post: 17th July 2006, 02:36 PM
  5. Kix Scripts
    By catbert in forum Scripts
    Replies: 5
    Last Post: 27th September 2005, 01:24 AM

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
  •