Q. How can a script set an environment variable to the logged on users default printer?
Jerold Schulman
November 29, 2006
1 Min Read
I have scripted ListDefault.bat to set an environment variable to the logged on user's default printer.
The syntax for using ListDefault.bat is:
[call] ListDefault prt
where Prt is a call directed environment variable that will contain the user's default printer.
NOTE: ListDefault.bat uses REG.EXE, built into Windows XP, Windows Server 2003, and later operating systems, or installed from the Windows 2000 Support Tools.
ListDefault.bat contains:
@echo offif {%1}=={} @echo ListDefault Printer&goto :EOFsetlocalset prt=NONEfor /f "Tokens=1 Delims=," %%a in ('REG query "HKCUSoftwareMicrosoftWindows NTCurrentVersionWindows" /V Device^|find "REG_SZ"') do ( set prt=%%a)set prt=%prt:*REG_SZ=%set wrk=%prt:~1%set wrk=%wrk: =%:loopif "%wrk:~0,1%" EQU " " set wrk=%wrk:~1%&goto loopendlocal&set %1=%wrk%
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like