Windows Thread, Setting a permanent default printer. in Technical; Hi,
OK, this one has been bugging me for a while but been on the back burner. Through the school ...
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
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
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??
'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.
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):
Code:
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:
Code:
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
[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
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?
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.
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
Code:
if (computerName = "BillsPC") then WshNetwork.AddWindowsPrinterConnection "\\BensServer\a_network_printer"
Add these at the end for any unusual printer mappings.
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
Code:
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.