Windows Thread, Default Printer Batch File in Technical; Hello,
I would like a batch file to rung at system startup/userlogon to set the default printer for all users. ...
-
11th April 2008, 01:50 PM #1
- Rep Power
- 14
Default Printer Batch File
Hello,
I would like a batch file to rung at system startup/userlogon to set the default printer for all users. I set it as administator but it then doesn't change for users. I can't really put it in the logon.bat as its only needed for one room and the other rooms have a different default.
Thanks
-
-
IDG Tech News
-
11th April 2008, 02:00 PM #2 We tend to do ours with a batchfile that runs at user login using con2prt to map..
-
-
11th April 2008, 02:42 PM #3 How about a .vbs script?
' VBScript.
Set net = WScript.CreateObject("wscript.network")
net.AddWindowsPrinterConnection "\\server\printer"
net.AddWindowsPrinterConnection "\\server\printer2"
net.SetDefaultPrinter "\\server\printer"
I got fed up of having different scripts for each OU so made a new one from some examples on the web that maps a few general printers, checks the OU of the Computer then maps any specific ones after that. It also looks to see if the current user is a member of a colour printer group, if so they get it mapped automatically
Hopefully should be rolling that out in the summer on the top level policy so when staff move offices their default printer changes as well.
-
-
11th April 2008, 03:26 PM #4 
Originally Posted by
karldenton
Hello,
I would like a batch file to rung at system startup/userlogon to set the default printer for all users. I set it as administator but it then doesn't change for users. I can't really put it in the logon.bat as its only needed for one room and the other rooms have a different default.
Thanks
You have to do this as a user script because (as you've found!) things like default printer are user specific.
There's a million (!) ways to do it but basically, you need to determine which room you're in and then set the default appropriately. Assuming you put computers into specific OUs based on rooms then your script just needs to find the OU and then map accordingly - there are loads of examples here about how to do this.
The nice, new, sexy way to do this is with group policy preferences - we're still rolling out the extension to our workstations so I haven't yet tried this but I think it has the potential to make life much easier :-)
-
-
14th April 2008, 10:03 AM #5
- Rep Power
- 14
Thanks for the replys.
I've got a batch file, which works:
' Option Explicit
Dim objNetwork, strUNCPrinter, strUNCPrinter1, strUNCPrinter2
strUNCPrinter = "\\2003server\libraryb1430"
Set objNetwork = CreateObject("WScript.Network")
Set WSHPrinters = objNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
'objNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
Next
'end delete existing printers
objNetwork.AddWindowsPrinterConnection strUNCPrinter
objNetwork.SetDefaultPrinter strUNCPrinter
WScript.Quit
Is it possible to asign this to a computer OU rather than user?
Thanks
Karl
-
-
14th April 2008, 11:39 AM #6 We used to have a script that had that loop counter in there but it never seemed to work right, if you want to delete all network printers before mapping try this...
'****************************
'Deletes old network printers
'****************************
On error Resume Next
Dim cNetCommands, vPrinterName, vPrinterPath
Set cNetCommands = WScript.CreateObject("WScript.Network")
Set vPrinterPath = cNetCommands.EnumPrinterConnections
For Each vPrinterName in vPrinterPath
cNetCommands.RemovePrinterConnection(vPrinterName)
Next
Wscript.Quit
Seems to work a lot more reliably for me 
As for assigning to computers this link may prove useful
Logon Script Example Assign Printer - RUNDLL32 PRINTUI.DLL
Last edited by gshaw; 14th April 2008 at 11:42 AM.
-
-
14th April 2008, 12:20 PM #7 As others have basically said... there's no point re-inventing the wheel. Check out Scripting Printer Addition Based on Location - EduGeek.net Wiki and if others have anything to add please do add it to the wiki.
-
-
14th April 2008, 12:38 PM #8
- Rep Power
- 14
OK guys, thanks foe the help.
Like i said, i have this vbs file which works fine when you run it as any user. I have put it in a shared location on the network. In gp, user config, windows settings, scripts, logon i have put a path to a logon script, which is :
\\2003server\SharedArea\ITTechnician\LibraryPrinte r\liblogon.bat
The script executes:
"cscript.exe \\2003server\SharedArea\ITTechnician\LibraryPrinte r\libdefault.vbs".
Done a gpupdate /force but still does't seem to work.
Any ideas.
Thanks again
-
-
14th April 2008, 12:49 PM #9 
Originally Posted by
Ric_
Hmm, I should probably add my enhancements
-
-
14th April 2008, 12:50 PM #10
- Rep Power
- 12
we put a shortcut in all users > startup from a shair on the server that let students and staff have read access, works a treat
-
-
14th April 2008, 01:01 PM #11 karl: It appears that you have a vbscript allready and not a batch script.
gshaw: Doesn't your script remove ALL printers and not just network ones?
Ben
-
-
14th April 2008, 01:47 PM #12 
Originally Posted by
karldenton
OK guys, thanks foe the help.
Like i said, i have this vbs file which works fine when you run it as any user. I have put it in a shared location on the network. In
gp, user config, windows settings, scripts, logon i have put a path to a logon script, which is :
\\2003server\SharedArea\ITTechnician\LibraryPrinte r\liblogon.bat
The script executes:
"cscript.exe \\2003server\SharedArea\ITTechnician\LibraryPrinte r\libdefault.vbs".
Instead of having the batch file, just call the VBScript directly from the GPO.
-
-
23rd March 2010, 03:18 PM #13 We got printers installed on each machine all printing to the same 2 printers one colour and one mono
i wanna change the default with out going to each machine i can do it locally or creating a startup bat file using defprint but i wanna do it like this because im lazy lol
defprint \\suite04 /d "IP_192.168.1.188"
defprint \\suite05 /d "IP_192.168.1.188"
but i cant seem to find the right switches any ideas? i dont really want to use a script or something that runs at starts up but ran once and thats it.
thanks
chris
-
-
23rd March 2010, 06:16 PM #14 The below works fine for me. If I'm honest a friend sent it to me... But I'm not! It's MINE! ALL MY OWN WORK!!!!

This also works to apply any users settings to a computer regardless of who logs into it.
For script to run on computers use Loopback processing in Merge Mode
That would allow you to apply a script to a Computer Account but using the User section of the policy.
To set it up what you need to do is:
1. Create a Group Policy with the Loopback Policy enabled:
Computer Configuration --> Administrative Templates --> System --> Group Policy
User Group Policy loopback processing mode: Enabled & Merge
2. Create a Group Policy attached to the OU containing the computer account with the script in the:
User Configuration --> Windows Settings --> Scripts Logon --> printers.vbs.
The Replace operation stops all other User based policies applying there and only uses those that would apply to the Computer OU.
The Merge operation uses the normal User based policies as well, but any policies set on the Computer OU take precedence.
Script for automated mapping of printer according to room number:
rem ** Next line must not be deleted **
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
rem ** Setup new printer connection **
WshNetwork.AddWindowsPrinterConnection "\\server\HP"
rem ** Setup default printer **
WshNetwork.SetDefaultPrinter "\\server\HP"
-
SHARE:
Similar Threads
-
By martyn in forum Scripts
Replies: 13
Last Post: 20th February 2008, 05:29 PM
-
By meastaugh1 in forum Windows
Replies: 2
Last Post: 17th January 2008, 09:02 PM
-
By MrLudwig in forum Windows
Replies: 13
Last Post: 8th December 2007, 03:40 AM
-
By macca in forum Windows
Replies: 5
Last Post: 3rd May 2007, 09:20 AM
-
By beeswax in forum Scripts
Replies: 9
Last Post: 3rd March 2006, 08:48 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
-
Forum Rules