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 10 of 11 FirstFirst ... 67891011 LastLast
Results 136 to 150 of 165
Scripts Thread, A Printer Script in Coding and Web Development; Here is a copy of the script we use here. I use function defined in the top to do the ...
  1. #136

    ZeroHour's Avatar
    Join Date
    Dec 2005
    Location
    Edinburgh, Scotland
    Posts
    5,693
    Thank Post
    947
    Thanked 1,355 Times in 828 Posts
    Blog Entries
    1
    Rep Power
    451

    Re: A Printer Script

    Here is a copy of the script we use here.
    I use function defined in the top to do the work and we use the built in MS agent to provide feedback to the users. It should be able to figure it all out anyway.
    The function LogtoEvent is used to log things happening in the script to the event log.
    It has 3 states although you wont use them all. I have found this to be very useful for diagnosing dodgy printers/drivers that cause the script to fail.
    Its still not really noob friendly but anyone with a little VBS experience should understand it.
    Look out for {change} areas in the script also.

    Good luck
    Attached Files Attached Files

  2. #137
    linkazoid's Avatar
    Join Date
    May 2007
    Location
    London
    Posts
    653
    Thank Post
    120
    Thanked 90 Times in 74 Posts
    Rep Power
    79

    Re: A Printer Script

    sorry to dig up a slightly old thread, but i have just managed to get this to work.

    It wasnt working before because of the LCase, changed this and it work on some rooms but not other becase they are lowercase, is there a way to incorperate both, withotut having to rename the PC's?

    Cheers

    Mike

  3. #138

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    London
    Posts
    7,592
    Thank Post
    109
    Thanked 770 Times in 598 Posts
    Rep Power
    183

    Re: A Printer Script

    @linkazoid: The LCase just changes the name to lowercase so that you can inspect the string without worrying about case - changing to uppercase would have done the same job. Does that make sense?

  4. #139

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    London
    Posts
    7,592
    Thank Post
    109
    Thanked 770 Times in 598 Posts
    Rep Power
    183

    Re: A Printer Script

    Since the wiki has moved, some of the extra bits for this script have become lost... if you would like to go to Scripting Printer Addition Based on Location - EduGeek.net Wiki and re-contribute all the different additions it would be great
    Last edited by ZeroHour; 6th April 2008 at 01:50 AM.

  5. #140

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,897
    Thank Post
    3,420
    Thanked 1,081 Times in 997 Posts
    Rep Power
    369

    Re: A Printer Script

    Just a case of using the split function instead using left or right functions makes it easier if there is a common demoninator in the string ie a - symbol to seperate room name from machine number or w/e

  6. #141

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,216
    Thank Post
    893
    Thanked 1,773 Times in 1,529 Posts
    Blog Entries
    12
    Rep Power
    461

    Re: A Printer Script

    Quote Originally Posted by originofsymmetry
    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

    [hr]


    Hi

    I have used The script above but it doesn't work, any ideas?

    This is my script

    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 "HC-IT1-"
    WshNetwork.AddWindowsPrinterConnection "\\HC-Print\Printer2"
    WshNetwork.AddWindowsPrinterConnection "\\HC-Print\Printer2"
    WshNetwork.SetDefaultPrinter "\\HC-Print\Printer2"
    ' WScript.Echo "No default printers added"
    End Select
    This bit i am lost with this:
    Select Case (Left(computerName, 5))
    Case "HC-IT1-"
    Is this the computer name?

    Please help.

    Z

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

    Yes, the first line is selecting the first five characters of the computer name, from the left. (eg if computername is HC-IT1-001, then HC-IT is used). You may want to adjust the 5 to 7 based on the script you provided.

    If your computer naming scheme follows a similar pattern, then you should be ok.

  8. #143

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,216
    Thank Post
    893
    Thanked 1,773 Times in 1,529 Posts
    Blog Entries
    12
    Rep Power
    461

    Re: A Printer Script

    OK i have altered that but when i run (by double clicking it) the script it does nothing.

    Any ideas please?

    Thanks

    Z

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

    In the second line change HC-IT1- to hc-it1-

    The reason it needs to be lowercase is because line 6 in your script changes the computername variable to lowercase.

  10. #145

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,216
    Thank Post
    893
    Thanked 1,773 Times in 1,529 Posts
    Blog Entries
    12
    Rep Power
    461

    Re: A Printer Script

    Good stuff!

    What would i do if i need to add another printer in the same room please?

    Thanks

    Z

  11. #146
    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

    So, this is the part of your script that assigns the printers:

    Quote Originally Posted by FN-Greatermanchester
    Select Case (Left(computerName, 7))
    Case "hc-it1-"
    WshNetwork.AddWindowsPrinterConnection "\\HC-Print\Printer2"
    WshNetwork.AddWindowsPrinterConnection "\\HC-Print\Printer2"
    WshNetwork.SetDefaultPrinter "\\HC-Print\Printer2"
    ' WScript.Echo "No default printers added"
    End Select
    Lines 3 and 4 seem to be duplicated. You can just change the UNC of the printer share on line 4. Then duplicate and modify the UNC as necessary for additional printers.

    For example, the following would assign printer1 and printer2 (default) on computer names beginning with hc-it1-. Printer3 (default) and printer4 will be assigned to computer names beginning with hc-it2-:

    Code:
    Select Case (Left(computerName, 7))
    Case "hc-it1-"
    WshNetwork.AddWindowsPrinterConnection "\\HC-Print\Printer2"
    WshNetwork.AddWindowsPrinterConnection "\\HC-Print\Printer1"
    WshNetwork.SetDefaultPrinter "\\HC-Print\Printer2"
    
    Case "hc-it2-"
    WshNetwork.AddWindowsPrinterConnection "\\HC-Print\Printer3"
    WshNetwork.AddWindowsPrinterConnection "\\HC-Print\Printer4"
    WshNetwork.SetDefaultPrinter "\\HC-Print\Printer3"
    
    Case Else
    ' WScript.Echo "No default printers added"
    End Select

  12. #147

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,216
    Thank Post
    893
    Thanked 1,773 Times in 1,529 Posts
    Blog Entries
    12
    Rep Power
    461

    Re: A Printer Script

    Thanks, will fully test when we get back.

    Thanks

    Z

  13. #148

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,216
    Thank Post
    893
    Thanked 1,773 Times in 1,529 Posts
    Blog Entries
    12
    Rep Power
    461

    Re: A Printer Script

    Sorry to double post, but just in case meastaugh1 already read my last post, so i didn't edit.

    Anyway can this be added to a start-up script, I ask this because I want to introduce this on certain computers only for now. I only want it to work on one ICT room not all the computers in the school. If not how do I adapt it so it will work with a start-up script please?

    Thanks

    Z

  14. #149
    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

    Hmm, network printer mappings are per-user connections. To deploy to a testbed of computers, I suggest you stick it in a GPO in loopback merge mode and deploy it as a login script.

    Having said that, you can add a network printer mapping on a computer for all users. I'm sure you'd only need to run it once on each computer, and wouldn't need to be run as a startup script.

    http://maisonbisson.com/blog/post/11106

  15. #150

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,216
    Thank Post
    893
    Thanked 1,773 Times in 1,529 Posts
    Blog Entries
    12
    Rep Power
    461

    Re: A Printer Script

    Ok I will try loopback when I get back

    So if i add the following to a .bat script and set it as a start-up script it should work?

    rundll32 printui.dll,PrintUIEntry /ga /n\\printers\%printername%
    Thank you for all your help

    Z

SHARE:
+ Post New Thread
Page 10 of 11 FirstFirst ... 67891011 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
  •