Solved

Setting default printer in batch file based on username

Posted on 2013-05-17
5
534 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 84

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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

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

This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

808 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