Solved

Setting default printer in batch file based on username

Posted on 2013-05-17
5
523 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 82

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

Want to promote your upcoming event?

Are you going to an event? Are you going to be exhibiting at a tradeshow? Talking at a conference? Using a promotional banner in your email signature ensures that your organization’s most important contacts stay in the know and can potentially spread the word about the event.

Join & Write a Comment

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
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...
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now