Solved

Setting default printer in batch file based on username

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

Will my email signature work in Office 365?

You've built an email signature using raw HTML code in Office 365, but you can't review how it looks with Transport Rules. So you have to test it over and over again before it can be used. Isn't this a bit of a waste of your time? Wouldn't a WYSIWYG editor make it a lot easier?

Question has a verified solution.

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

A few months ago I had an issue with LaserJet 1020 printer which was installed to XP and Windows 7.  It was installed to XP and working, but when I tried to connect from a Windows 7 PC, it would attempt connection and then fail.  Sometimes the Spool…
This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
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…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

863 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

19 Experts available now in Live!

Get 1:1 Help Now