Link to home
Start Free TrialLog in
Avatar of killefer762
killefer762

asked on

Setting default printer in batch file based on username

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....
Avatar of ZabagaR
ZabagaR
Flag of United States of America image

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
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of killefer762
killefer762

ASKER

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
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
It was a permission issue, it works now :)