Solved

Setting default printer in batch file based on username

Posted on 2013-05-17
5
531 Views
Last Modified: 2013-05-17
Trying to set default printers on a terminal server in a batch file.


This command sets the current user to the zebra printer

c:\windows\system32\RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "[NWCC] Zebra ZM400 (203 dpi) - ZPL (Recv 2)"

When I add an if to test the username it doesn't work:

if %username%=="myuser"   c:\windows\system32\RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "[NWCC] Zebra ZM400 (203 dpi) - ZPL (Recv 2)"

I played around with the quotes with no luck....
0
Comment
Question by:killefer762
  • 3
5 Comments
 
LVL 15

Expert Comment

by:ZabagaR
ID: 39176010
I have one as a vb script that works on a terminal server. You'd just have to name it something.vbs and drop it in the all user's \Start Meu\Startup\ folder so it runs whenever people log in.

This is the code below: I'm setting the Administrator's account to default to my HP 4000 printer.
--------------------------------------------------------------------------------------------------------------------
dim objNetwork, wshShell
set objNetwork = createobject("Wscript.Network")
Set wshShell = WScript.CreateObject( "WScript.Shell" )
User = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )

if User = "Administrator" then
objNetwork.SetDefaultPrinter "HP Laserjet 4000"
end if
0
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 39176147
You need an "/i" in the "if" to make the comparison case insensitive, and you need quotes around the %username% variable as well:
if /i "%username%"=="myuser"  %Systemroot%\system32\rundll32.exe PRINTUI.DLL,PrintUIEntry /y /n "[NWCC] Zebra ZM400 (203 dpi) - ZPL (Recv 2)"

Open in new window

0
 

Author Comment

by:killefer762
ID: 39176154
That would work...I need multiple users on this script and I can load it in group policy to run..but only the administrator seems to work on this..since its a terminal server there is no path to c:\windows\system32 I think is the issue ?

dim objNetwork, wshShell
set objNetwork = createobject("Wscript.Network")
Set wshShell = WScript.CreateObject( "WScript.Shell" )
User = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )

if User = "administrator2" then
objNetwork.SetDefaultPrinter "[NWCC] Zebra ZM400 (203 dpi) - ZPL (Recv 2)"
Elseif User = "administrator" then
objNetwork.SetDefaultPrinter "[NWCC] Zebra ZM400 (203 dpi) - ZPL (Recv 2)"
end if
0
 

Author Comment

by:killefer762
ID: 39176191
I changed it to read:

if /i "%username%"=="wtcoolrecv"  %Systemroot%\system32\rundll32.exe PRINTUI.DLL,PrintUIEntry /y /n "[NWCC] Zebra ZM400 (203 dpi) - ZPL (Recv 2)"

But default printer doesn't change....
defprinter.JPG
0
 

Author Comment

by:killefer762
ID: 39176292
It was a permission issue, it works now :)
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question