Poll: Was this script helpful?

Be advised that this is a public poll: other users can see the choice(s) you selected.

+ Post New Thread
Page 9 of 11 FirstFirst ... 567891011 LastLast
Results 121 to 135 of 165
Scripts Thread, A Printer Script in Coding and Web Development; We already have a working setup using con2prt to allocate printers to our fat clients depending on their OU. I ...
  1. #121
    Andi's Avatar
    Join Date
    Feb 2007
    Location
    Newport, South Wales
    Posts
    276
    Thank Post
    52
    Thanked 4 Times in 4 Posts
    Rep Power
    16

    Re: A Printer Script

    We already have a working setup using con2prt to allocate printers to our fat clients depending on their OU. I was just looking for a solution for my thin clients and this is great, thanks again.

  2. #122
    tomscaper's Avatar
    Join Date
    Jul 2006
    Posts
    814
    Thank Post
    118
    Thanked 29 Times in 15 Posts
    Rep Power
    22

    Re: A Printer Script

    This is our printer script


    'Printer Script
    'This script checks the Computer Group Membership
    'and installs depending on the group.
    Option explicit
    dim objNetwork, objComputer, ObjPrinter
    dim strDomain, strComputerName
    Set objNetwork = WScript.CreateObject("Wscript.Network")
    strDomain = objNetwork.UserDomain
    strComputerName = objNetwork.ComputerName
    Set objComputer = GetObject("WinNT://" & strDomain & "/" & strComputerName & ",computer")
    Set objPrinter = CreateObject("WScript.Network")

    If isComputerMember("LRC") Then
    objPrinter.AddWindowsPrinterConnection "\\prnt_svr\printer1"
    objPrinter.SetDefaultPrinter "\\prnt_svr\printer1"
    End If

    Function IsComputerMember(sGroup)
    Dim oGroup
    on error resume next
    Set oGroup = GetObject("WinNT://" & strDomain & "/" & sGroup & ",group")
    IsComputerMember = CBool(oGroup.IsMember(objComputer.ADsPath & "$"))
    Set oGroup = Nothing
    If not Err.Number = 0 Then
    'isComputerMember could not locate group
    end if
    on error goto 0
    End Function
    We created groups in the active directory, and added the computers to those groups, this was a much easier way as you can set up the printer scripts and add computers as you get them to the different groups.

    One question i am wondering is that if anyone know how to rename the printer when it is added in the script, like you can make a drive mapping and rename the drive mapping to something that kids can understand.

    Tom

  3. #123
    originofsymmetry's Avatar
    Join Date
    Jun 2007
    Posts
    186
    Thank Post
    9
    Thanked 14 Times in 11 Posts
    Rep Power
    17

    Re: A Printer Script

    Right I have tried Rics scripts but am not getting any success, heres the score:
    Servername=testserv
    Printers=ENGLISH_1. ENGLISH_2, MATHS_1, MATHS_2 * They are attached to the server, not directly to the clients, they are shared.
    The clients are organised in OU's - english and maths, with the following names: eng01, eng02, mat01, mat02

    My problem seems to arise with the first script, installing printer drivers:

    Code:
    On Error Resume Next
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    Set oPrinters = WshNetwork.EnumPrinterConnections
     
    For i = 0 to oPrinters.Count - 1 Step 2
                On Error Resume Next
    	    if Left(oPrinters.Item(i), 3) <> "lpt" And Left(oPrinters.Item(i), 3) <> "usb" then
                 	WshNetwork.RemovePrinterConnection oPrinters.Item(i+1), true, true
                else WScript.Echo "No network printers found"
                end if
    Next
     
    Dim printServer
    printServer = "testserv"
     
    WshNetwork.AddWindowsPrinterConnection "\\"testserv"\ENGLISH_1"
    WshNetwork.AddWindowsPrinterConnection "\\"testserv"\ENGLISH_2"
    WshNetwork.AddWindowsPrinterConnection "\\"testserv"\MATHS_1"
    WshNetwork.AddWindowsPrinterConnection "\\"testserv"\MATHS_2" 
    
    oPrinters = WshNetwork.EnumPrinterConnections
    For i = 0 to oPrinters.Count - 1 Step 2
                On Error Resume Next
    	    if Left(oPrinters.Item(i), 3) <> "lpt" And Left(oPrinters.Item(i), 3) <> "usb" then
                 	WshNetwork.RemovePrinterConnection oPrinters.Item(i+1), true, true
                else WScript.Echo "No network printers found"
                end if
    Next
    This script used to run just after the user typed there name and Applyng Computer Configuration and Running Logon Scripts would show, but for some reason, this has stopped happening - the script is located in GMPC and is appleid to eng01, eng02.....

    The second os the user logon script which is run for all users using a STUDENT group I created and assigined eveyone to

    Code:
    On Error Resume Next
     
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    Set oPrinters = WshNetwork.EnumPrinterConnections
     
    Dim computerName
    computerName = LCase(WshNetwork.ComputerName)
    Dim printServer
    printServer = "testserv"
    
    Select Case (Left(computerName, 5))
    	Case "eng01"
    		WshNetwork.AddWindowsPrinterConnection "\\"testserv"\ENGLISH_1"
    		WshNetwork.SetDefaultPrinter "\\"testserv"\ENGLISH_2"
    	        objNetwork.SetDefaultPrinter "\\testserv\ENGLISH_1"
            Case "eng02"
    		WshNetwork.AddWindowsPrinterConnection "\\"testserv"\ENGLISH_1"
    		WshNetwork.SetDefaultPrinter "\\"testserv"\ENGLISH_2"
    	        objNetwork.SetDefaultPrinter "\\testserv\ENGLISH_1"
            Case "mat01"
    		WshNetwork.AddWindowsPrinterConnection "\\"testserv"\MATHS_1"
    		WshNetwork.SetDefaultPrinter "\\"testserv"\MATHS_2"
                    objNetwork.SetDefaultPrinter "\\testserv\MATHS_1"
            Case "mat02"
    		WshNetwork.AddWindowsPrinterConnection "\\"testserv"\MATHS_1"
    		WshNetwork.SetDefaultPrinter "\\"testserv"\MATHS_2"
                    objNetwork.SetDefaultPrinter "\\testserv\MATHS_1"
            Case Else
    		' WScript.Echo "No default printers added"
    End Select
    When using this script on its own I receive no errors from Windows so I assume there are no errors with, it, just the driver install one, and how can I get it to apply again, it just stopped seemingly for no reason.

    Sorry for the big post but wanted to give as much info as possible thnx

  4. #124
    meastaugh1's Avatar
    Join Date
    Jul 2006
    Location
    London/Hertfordshire
    Posts
    890
    Thank Post
    69
    Thanked 85 Times in 70 Posts
    Rep Power
    32

    Re: A Printer Script

    I assume you are just assigning printers to XP clients, and not thin clients? If so, then I'm sure you just need the one logon script:

    Code:
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    Set oPrinters = WshNetwork.EnumPrinterConnections
    
    Dim computerName
    computerName = LCase(WshNetwork.ComputerName)
    
    For i = 0 to oPrinters.Count - 1 Step 2
                On Error Resume Next
    		if Left(oPrinters.Item(i), 3) <> "lpt" And Left(oPrinters.Item(i), 3) <> "usb" then
                 	WshNetwork.RemovePrinterConnection oPrinters.Item(i+1), true, true
                else WScript.Echo "No network printers found"
                end if
    Next
    
    Select Case (Left(computerName, 5))
    Case "eng01"
          WshNetwork.AddWindowsPrinterConnection "\\"testserv"\ENGLISH_1"
          WshNetwork.SetDefaultPrinter "\\"testserv"\ENGLISH_2"
               objNetwork.SetDefaultPrinter "\\testserv\ENGLISH_1"
            Case "eng02"
          WshNetwork.AddWindowsPrinterConnection "\\"testserv"\ENGLISH_1"
          WshNetwork.SetDefaultPrinter "\\"testserv"\ENGLISH_2"
               objNetwork.SetDefaultPrinter "\\testserv\ENGLISH_1"
            Case "mat01"
          WshNetwork.AddWindowsPrinterConnection "\\"testserv"\MATHS_1"
          WshNetwork.SetDefaultPrinter "\\"testserv"\MATHS_2"
                    objNetwork.SetDefaultPrinter "\\testserv\MATHS_1"
            Case "mat02"
          WshNetwork.AddWindowsPrinterConnection "\\"testserv"\MATHS_1"
          WshNetwork.SetDefaultPrinter "\\"testserv"\MATHS_2"
                    objNetwork.SetDefaultPrinter "\\testserv\MATHS_1"
    	Case Else
    		' WScript.Echo "No default printers added"
    End Select
    What's the naming convention of your workstations? You are aware that printers are being assigned according to first five characters of the computer name, and not the first five characters of the OU in which they reside?

  5. #125
    originofsymmetry's Avatar
    Join Date
    Jun 2007
    Posts
    186
    Thank Post
    9
    Thanked 14 Times in 11 Posts
    Rep Power
    17

    Re: A Printer Script

    the naming convention for the computers is the first three letters from the department then the computer number, I dont have it all split for room number, the number (01)etc. just goes on for a department in whole, may it be the cause? And yes, its just to a bunch of XP clients, thanks for clearing that bit up

  6. #126
    meastaugh1's Avatar
    Join Date
    Jul 2006
    Location
    London/Hertfordshire
    Posts
    890
    Thank Post
    69
    Thanked 85 Times in 70 Posts
    Rep Power
    32

    Re: A Printer Script

    I see, that sounds alright then. So, the logon script isn't working? Have you tried running it interactively as a logged on student user?

  7. #127
    originofsymmetry's Avatar
    Join Date
    Jun 2007
    Posts
    186
    Thank Post
    9
    Thanked 14 Times in 11 Posts
    Rep Power
    17

    Re: A Printer Script

    What do you mean by that? Me logging in to a client on a machine? If so then I have tried that

  8. #128
    meastaugh1's Avatar
    Join Date
    Jul 2006
    Location
    London/Hertfordshire
    Posts
    890
    Thank Post
    69
    Thanked 85 Times in 70 Posts
    Rep Power
    32

    Re: A Printer Script

    And no errors, nothing in the event log?

    How about changing
    Code:
          WshNetwork.AddWindowsPrinterConnection "\\"testserv"\ENGLISH_1"
          WshNetwork.SetDefaultPrinter "\\"testserv"\ENGLISH_2"
    to
    Code:
          WshNetwork.AddWindowsPrinterConnection "\\testserv\ENGLISH_1"
          WshNetwork.SetDefaultPrinter "\\testserv\ENGLISH_2"

  9. #129
    originofsymmetry's Avatar
    Join Date
    Jun 2007
    Posts
    186
    Thank Post
    9
    Thanked 14 Times in 11 Posts
    Rep Power
    17

    Re: A Printer Script

    Yay!! I got it working with this:

    Code:
    On Error Resume Next
    
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    Set oPrinters = WshNetwork.EnumPrinterConnections
    
    Dim computerName
    computerName = LCase(WshNetwork.ComputerName)
    
    For i = 0 to oPrinters.Count - 1 Step 2
                On Error Resume Next
    		if Left(oPrinters.Item(i), 3) <> "lpt" And Left(oPrinters.Item(i), 3) <> "usb" then
                 	WshNetwork.RemovePrinterConnection oPrinters.Item(i+1), true, true
                else WScript.Echo "No network printers found"
                end if
    Next
    
    Select Case (Left(computerName, 5))
    	Case "eng01"
    		WshNetwork.AddWindowsPrinterConnection "\\testserv\english-1"
    		WshNetwork.AddWindowsPrinterConnection "\\testserv\english-2"
    		WshNetwork.SetDefaultPrinter "\\testserv\english-1"
    	Case "eng02"
    		WshNetwork.AddWindowsPrinterConnection "\\testserv\english-1"
    		WshNetwork.AddWindowsPrinterConnection "\\testserv\english-2"
    		WshNetwork.SetDefaultPrinter "\\testserv\english-2"
    	Case "mat01"
    		WshNetwork.AddWindowsPrinterConnection "\\testserv\maths-1"
    		WshNetwork.AddWindowsPrinterConnection "\\testserv\maths-2"
                    WshNetwork.SetDefaultPrinter "\\testserv\maths-1"
    	Case "mat02"
    		WshNetwork.AddWindowsPrinterConnection "\\testserv\maths-1"
    		WshNetwork.AddWindowsPrinterConnection "\\testserv\maths-2"
    		WshNetwork.SetDefaultPrinter "\\testserv\maths-2"
            Case Else
    		' WScript.Echo "No default printers added"
    End Select

    Thnx to everyone who's helped and to Ric_ for writing this script
    Now, to finish off, I'd like to be able to nuke existing connections when a user logs off as opposed to on, so would I use this script as is, or would I need to add anything to it?

    Code:
    For i = 0 to oPrinters.Count - 1 Step 2
                On Error Resume Next
    		if Left(oPrinters.Item(i), 3) <> "lpt" And Left(oPrinters.Item(i), 3) <> "usb" then
                 	WshNetwork.RemovePrinterConnection oPrinters.Item(i+1), true, true
                else WScript.Echo "No network printers found"
                end if
    Next

  10. #130
    meastaugh1's Avatar
    Join Date
    Jul 2006
    Location
    London/Hertfordshire
    Posts
    890
    Thank Post
    69
    Thanked 85 Times in 70 Posts
    Rep Power
    32

    Re: A Printer Script

    Yeah, you'd need to start the script with:
    Code:
    On Error Resume Next
    
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    Set oPrinters = WshNetwork.EnumPrinterConnections

  11. #131
    mullet_man's Avatar
    Join Date
    Oct 2005
    Location
    Oldham
    Posts
    726
    Thank Post
    34
    Thanked 46 Times in 45 Posts
    Rep Power
    26

    Re: A Printer Script

    [quote="tomscaper"]This is our printer script


    One question i am wondering is that if anyone know how to rename the printer when it is added in the script, like you can make a drive mapping and rename the drive mapping to something that kids can understand.

    Tom
    Thats what I was hoping could be done as well?

    Does anyone know how to do this?

  12. #132
    TechSupp's Avatar
    Join Date
    Mar 2007
    Location
    South Yorkshire
    Posts
    1,876
    Thank Post
    295
    Thanked 120 Times in 101 Posts
    Rep Power
    40

    Re: A Printer Script

    As far as I know you can, I've got this running in my script but I have to admit not sure it works 100%. Will have a look in the morning and post it if I have it. Maybe it will help.

    Just had a look and this is what I have in my script to name the printers. As I said it works for some of the printers but not everyone for some reason. Not too bothered as everyone has not got used to the names that appear and changing them now would only confuse them.

    '// Map Printers
    network.AddWindowsPrinterConnection printer1 , "Black and White Printer"
    network.AddWindowsPrinterConnection printer2 , "Colour Printer"
    network.AddWindowsPrinterConnection printer3 , "Colour Photocopier"

  13. #133

    ZeroHour's Avatar
    Join Date
    Dec 2005
    Location
    Edinburgh, Scotland
    Posts
    5,644
    Thank Post
    895
    Thanked 1,314 Times in 798 Posts
    Blog Entries
    1
    Rep Power
    444

    Re: A Printer Script

    I will post my script soon as its years of tweaking and contains code to help log errors and also provide some user feedback as well.
    Just trying to sanitise it for the real world

  14. #134
    mullet_man's Avatar
    Join Date
    Oct 2005
    Location
    Oldham
    Posts
    726
    Thank Post
    34
    Thanked 46 Times in 45 Posts
    Rep Power
    26

    Re: A Printer Script

    Thanks TechSupp I will see if I can get my printers named tomorow!!

  15. #135
    mullet_man's Avatar
    Join Date
    Oct 2005
    Location
    Oldham
    Posts
    726
    Thank Post
    34
    Thanked 46 Times in 45 Posts
    Rep Power
    26

    Re: A Printer Script

    Quote Originally Posted by TechSupp
    As far as I know you can, I've got this running in my script but I have to admit not sure it works 100%. Will have a look in the morning and post it if I have it. Maybe it will help.

    Just had a look and this is what I have in my script to name the printers. As I said it works for some of the printers but not everyone for some reason. Not too bothered as everyone has not got used to the names that appear and changing them now would only confuse them.

    '// Map Printers
    network.AddWindowsPrinterConnection printer1 , "Black and White Printer"
    network.AddWindowsPrinterConnection printer2 , "Colour Printer"
    network.AddWindowsPrinterConnection printer3 , "Colour Photocopier"
    That didn't work :-(

    Thanks.

SHARE:
+ Post New Thread
Page 9 of 11 FirstFirst ... 567891011 LastLast

Similar Threads

  1. logon script for printer
    By ozzy in forum Scripts
    Replies: 6
    Last Post: 22nd November 2007, 03:03 PM
  2. Printer Script
    By faza in forum Scripts
    Replies: 9
    Last Post: 14th September 2007, 08:30 AM
  3. Logon script & Printer script question.
    By Galway in forum Windows
    Replies: 3
    Last Post: 29th August 2007, 11:00 AM
  4. Add printer script not workling
    By mark in forum Windows
    Replies: 6
    Last Post: 15th September 2005, 10:07 AM
  5. Script to delete printer
    By tosca925 in forum Scripts
    Replies: 2
    Last Post: 31st August 2005, 07:45 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
  •