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\RUNDLL 32 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\RUNDLL 32 PRINTUI.DLL,PrintUIEntry /y /n "[NWCC] Zebra ZM400 (203 dpi) - ZPL (Recv 2)"
I played around with the quotes with no luck....
This command sets the current user to the zebra printer
c:\windows\system32\RUNDLL
When I add an if to test the username it doesn't work:
if %username%=="myuser" c:\windows\system32\RUNDLL
I played around with the quotes with no luck....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.Netw ork")
Set wshShell = WScript.CreateObject( "WScript.Shell" )
User = wshShell.ExpandEnvironment Strings( "%USERNAME%" )
if User = "administrator2" then
objNetwork.SetDefaultPrint er "[NWCC] Zebra ZM400 (203 dpi) - ZPL (Recv 2)"
Elseif User = "administrator" then
objNetwork.SetDefaultPrint er "[NWCC] Zebra ZM400 (203 dpi) - ZPL (Recv 2)"
end if
dim objNetwork, wshShell
set objNetwork = createobject("Wscript.Netw
Set wshShell = WScript.CreateObject( "WScript.Shell" )
User = wshShell.ExpandEnvironment
if User = "administrator2" then
objNetwork.SetDefaultPrint
Elseif User = "administrator" then
objNetwork.SetDefaultPrint
end if
ASKER
I changed it to read:
if /i "%username%"=="wtcoolrecv" %Systemroot%\system32\rund ll32.exe PRINTUI.DLL,PrintUIEntry /y /n "[NWCC] Zebra ZM400 (203 dpi) - ZPL (Recv 2)"
But default printer doesn't change....
defprinter.JPG
if /i "%username%"=="wtcoolrecv"
But default printer doesn't change....
defprinter.JPG
ASKER
It was a permission issue, it works now :)
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.Netw
Set wshShell = WScript.CreateObject( "WScript.Shell" )
User = wshShell.ExpandEnvironment
if User = "Administrator" then
objNetwork.SetDefaultPrint
end if