ninjabeaver Posted July 8, 2005 Posted July 8, 2005 Hi, OK, this one has been bugging me for a while but been on the back burner. Through the school network we have installed the networked printers through a simple script inside a batch file. That works great, but........... for example we have a PC in the staff room that also has a colour inkjet next to it. I would like this networked colour inkjet to be the default printer, but it always defaults to the black and white one next door. Anyone got any ideas how to set this to use the colour inkjet as default? I also have similar things happening around the school. Thanks
ChrisH Posted July 8, 2005 Posted July 8, 2005 Just use VB something like Set WshNetwork = WScript.CreateObject("WScript.Network") WshNetwork.SetDefaultPrinter "\\thiscomputer\colourpinter"
Mango_RW Posted July 8, 2005 Posted July 8, 2005 edit your printer script (Presuming your using VBScript) Add "SleepTime=15" - without quotes to the top of your script put the following in at the end. WScript.Sleep SleepTime*1000 WshNetwork.SetDefaultPrinter "\\[serverName]\StaffRoom-Colour" The reason your add a sleep time is so that the machine has enough chance to install the printer then set it, some machine are so quick at running the script it finishes before the printers are added and the default doesn't set. Our full script for staff room: rem ** Next line must not be deleted ** SleepTime=15 Set WshNetwork = CreateObject("WScript.Network") rem ** This will delete existing printers ** On Error Resume Next Set oPrinters = WshNetwork.EnumPrinterConnections For i = 1 to oPrinters.Count - 1 Step 2 WshNetwork.RemovePrinterConnection oPrinters.Item(i) Next WshNetwork.AddWindowsPrinterConnection "\\[serverName]\StaffRoom-Colour" rem ** Set Default Printer ** WScript.Sleep SleepTime*1000 WshNetwork.SetDefaultPrinter "\\[serverName]\StaffRoom-Laser"
ninjabeaver Posted July 8, 2005 Author Posted July 8, 2005 OK, perhaps 'script' was a bit too strong for what this is. I'm running a batch file with items like this in it. 'rundll32 printui.dll,PrintUIEntry /ga /c\\RM54-01 /n\\PHServer3\BWRoom53' with the PC number (RM54-01, RM54-02) etc going up until all the PC's in that room are covered. This is run once when the room has been re-imaged or a single PC is repaired, re-imaged etc. Now, if that printer is the only one in there then fine but if I want to add another printer but leave the first one as default it keeps reverting to the last one installed. I've never done VB Scripting either, and websites I can look at to workout how to do the above?? Thanks.
ChrisH Posted July 8, 2005 Posted July 8, 2005 You basically want something like this: 'Server Definitions Const File_Server = "\\FMDC1\" Const Print_Server = "\\FMDC2\" 'Printer definitions Const Room22_Mono = "Room22MonoPrinter" Const Room22_Colour = "Room22ColourPrinter" Const Room25_Mono = "Room25MonoPrinter" Const Room25_Colour = "Room25Colour" Const Room30_Mono = "Room30MonoPrinter" Const Room30_Colour = "Room30ColourPrinter" Set WshNetwork = WScript.CreateObject("WScript.Network") StrComputerName = Left(LCase(WshNetwork.ComputerName),4) StrComputerName = Left(LCase(WshNetwork.ComputerName),4) ' Delete existing network Printers For i = 0 to ObjPrinters.Count - 1 Step 2 On Error Resume Next if Left(ObjPrinters.Item(i), 3) <> "lpt" And Left(ObjPrinters.Item(i), 3) <> "usb" then WshNetwork.RemovePrinterConnection ObjPrinters.Item(i+1), true, true else WScript.Echo "No network printers found" end if Next ' Add Network Printers according to location Select Case (Left(StrComputerName, 4)) Case "it22" WshNetwork.AddWindowsPrinterConnection Print_server & Room22_Mono WshNetwork.AddWindowsPrinterConnection Print_server & Room22_Colour WshNetwork.SetDefaultPrinter Print_server & Room22_Mono Case Else ' WScript.Echo "No default printers added" End Select 'End printer Case Statements '************************* End Of Printer Setup ************************* This will remove all printers apart from local ones and add a printer according to teh computer anme. All the definitions are at the top in the constants. There are may VB script resources out there the Microsoft Script Centre is a good place to start.
tarquel Posted July 8, 2005 Posted July 8, 2005 But if thats to confusing for you (as you havent done VB scripting before), you could always try kixtart script files which - to me, are a bit more easy to understand I find. Here's my current one (its by no means finished ppl so no flaming please): DelPrinterConnection ("\\SERVERNAME\HP LaserJet 1300n") DelPrinterConnection ("\\SERVERNAME\HP LaserJet 1200 Series PCL 6") DelPrinterConnection ("\\SERVERNAME\hp LaserJet 1320") set computer="@wksta" $room=SubStr(@wksta,1,2) $client=SubStr(%clientname%,3,2) Select Case ($room="07") AddPrinterConnection ("\\SERVERNAME\HP LaserJet 1200 Series PCL 6") AddPrinterConnection ("\\SERVERNAME\hp LaserJet 1320") SetDefaultPrinter ("\\SERVERNAME\HP LaserJet 1200 Series PCL 6") EndSelect Select Case ($room="HU") AddPrinterConnection ("\\SERVERNAME\HP LaserJet 1300n") SetDefaultPrinter ("\\SERVERNAME\hp LaserJet 1300n") EndSelect (this file for me is called printer.kix) I have this in the 'netlogon' share of the server along with the kix32.exe and you just need to change: - the servername to what server is the print server - the room & client variable information to however you name/order the computers in your 'computername' - Change the printer(s) names and/or location to whatever their sharename (or full name is too) - You can add more sections and printers easily and its amazing how quick it works - even when there is a class of pupils logging on. You add it to your logon.bat (if you use one) as: echo - Mounting printers for this room or computer...please wait... echo. \\SERVERNAME\NETLOGON\kix32.exe \\SERVERNAME\NETLOGON\printer.kix (where servername is you DC most likely) search google for kixtart and you should find the site, although if ya want, I can always send you the file(s). A few of us (that I chat to) in powys use this system and it works great Cheers, and good luck. Nath 1
MkII Posted July 8, 2005 Posted July 8, 2005 looks familiar Nath hehe! [The client name is actually for my citrix clients so I don't see you need that bit]
Geoff Posted July 8, 2005 Posted July 8, 2005 Ric has a good printer vbs script. Any chance of posting it Ric? or shall I post my multilated version of it?
tarquel Posted July 8, 2005 Posted July 8, 2005 Oooops lol [yes - I've only learnt about this from mark and another bloke in powys btw] I thought it was for specific computer identifying i.e. 20 pc's in a room. I want one of those PC's to map a printer but not the others. Thought I could use both the Room and client variable to specify this sorta thing I would also like to add some way of basing it on user too - I'm sure it is fairly obvious (i.e. different scripts for different users etc but just simply right now...). Cheers Nath PS @ mark: Wynn just left a message of my phone wondering why he couldnt connect to the admin server - to quote "Can you think of a reason why that is?" ....lol I can... Its because the server isn't on lol ;)
ChrisH Posted July 8, 2005 Posted July 8, 2005 Looking at that Kix script I wouldnt say VB script syntax was any more difficult than kix. Maybe mine just looks a little complicated because I used constants for the printers name in the add printer commands?
MkII Posted July 8, 2005 Posted July 8, 2005 I would also like to add some way of basing it on user too - I'm sure it is fairly obvious (i.e. different scripts for different users etc but just simply right now...). I'm sure that'd be easy with kix - just find the user call. [LOL @ Wynn ]
Ric_ Posted July 8, 2005 Posted July 8, 2005 Here is the hallowed printer script. This copy may be slightly out of date. You will notice that it refers to a computer called SVRTS1 - this is a citrix server and that particular line moves the terminal's name into the computername variable so that the printer is mapped correctly. You may play about with it but don't slag it off too much - I knwo that it should be better documented and should probably involve some better error handling. You may also add single lines of the form if (computerName = "BillsPC") then WshNetwork.AddWindowsPrinterConnection "\\BensServer\a_network_printer" Add these at the end for any unusual printer mappings.printers.vbs
Mango_RW Posted July 19, 2005 Posted July 19, 2005 Here is the hallowed printer script. This copy may be slightly out of date. You will notice that it refers to a computer called SVRTS1 - this is a citrix server and that particular line moves the terminal's name into the computername variable so that the printer is mapped correctly. You may play about with it but don't slag it off too much - I knwo that it should be better documented and should probably involve some better error handling. You may also add single lines of the form if (computerName = "BillsPC") then WshNetwork.AddWindowsPrinterConnection "\\BensServer\a_network_printer" Add these at the end for any unusual printer mappings. Good Work! - we currently have seperate vbs files for each room but will now look at one file.
ChrisH Posted July 19, 2005 Posted July 19, 2005 You may want to use a case statement it will be neater.
StewartKnight Posted July 19, 2005 Posted July 19, 2005 to make the printer a default printer add the "default" work!! i.e. Dim oNetwork, sPrintPath Set oNetwork = CreateObject("WScript.Network") sPrintPath ="\\10.102.28.7\Science" oNetwork.AddWindowsPrinterConnection sPrintPath oNetwork.SetDefaultPrinter sPrintPath WScript.Quit
tosca925 Posted August 21, 2005 Posted August 21, 2005 Has any tried this script from stewartknight, it's just the thing i am looking for. I am not back in school till midweek just wondered if anyone had tried this? to make the printer a default printer add the "default" work!! i.e. Code: Dim oNetwork, sPrintPath Set oNetwork = CreateObject("WScript.Network") sPrintPath ="\\10.102.28.7\Science" oNetwork.AddWindowsPrinterConnection sPrintPath oNetwork.SetDefaultPrinter sPrintPath WScript.Quit _________________ Stewart Knight Network Manager Appleby Grammar School
tosca925 Posted August 21, 2005 Posted August 21, 2005 Sorry for the double posting but have got a second question regarding a default printer script? On our RIS images we have a PDF printer installed and have found out also that WSUS during office 2003 updates re-installs the MS Image Writer printer. Will a default printer script over rule one of these when run?
RobC Posted August 21, 2005 Posted August 21, 2005 If your script is set to run at user logon, then it will take precedence over any previous defaults. I think this goes for computer logon scripts as well, but not 100% sure on that.
Ric_ Posted August 22, 2005 Posted August 22, 2005 @tosca925: have you tried running the script to see if it changes the default back to your PDF writer? The script is designed to run at user logon (every logon) so I would imagine that there should be no issues.
E1uSiV3 Posted August 22, 2005 Posted August 22, 2005 Does anyone here use con2prt anymore? it has the option to set the default option when installing network printers, and i jus launch it using a batch file assigned in group policy at user logon
tosca925 Posted August 22, 2005 Posted August 22, 2005 Using the vbs script below, is there anyone you can edit this so in a previous post about setting a time out can be added to this script? Sorry but i am c**p when it comes to scripting. Dim oNetwork, sPrintPath Set oNetwork = CreateObject("WScript.Network") sPrintPath ="\\10.102.28.7\Science" oNetwork.AddWindowsPrinterConnection sPrintPath oNetwork.SetDefaultPrinter sPrintPath WScript.Quit
ChrisH Posted August 23, 2005 Posted August 23, 2005 What do you want to time out? You mean you dont want it to display an error if the printer isnt found?
Ric_ Posted August 23, 2005 Posted August 23, 2005 I'm sure that it times itself out (although an error may be printed). Try just running it as a batch script (use the //B switch).
ChrisH Posted August 23, 2005 Posted August 23, 2005 or add the line On Error Resume Next At the top. A lazy way but if it's just a simple script then....
tosca925 Posted August 23, 2005 Posted August 23, 2005 SleepTime=15 WScript.Sleep SleepTime*1000 Can these 2 lines be added to the script i posted above?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now