Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to rename printer at logon

Status
Not open for further replies.

twoody54

IS-IT--Management
Apr 11, 2002
150
US
Hi,

I want to rename autocreated printers when users logon to TS. Is there an easy way to do this? Basically I want to get rid of all the extra stuff after the name

ex) instead of HP4000 (from clientx) in session X
I want HP4000
 
Check this site out.

I've been playing with a modified RenamePrinter.bat file since my "DefaultPrinter" output string is like yours and not like what's in the original. The notes I left in the script should explain what happens at each step.

Code:
Rem Set the local variables
SetLocal

Rem Wait about 10 seconds to let the terminal server set up the printer...
rem Sleep 10

Rem Reads the default printer from the registry and creates "DefPrint.cmd" to store the info
"%SystemRoot%\Application Compatibility Scripts\acregl.exe" DefPrint.cmd DefaultPrinter "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows" "Device" ""

If Not Exist DefPrint.cmd (Call :Error 1) && (Goto EoF)

call DefPrint.cmd
del DefPrint.cmd

If Not Defined DefaultPrinter (Call :Error 2) && (Goto EoF)

REM :: this command should return something like this
REM :: "DefaultPrinter = PrinterName (from WORKSTATION) in session 5,winspool,TS010"
		
REM :: create variable %OldPrinterString% with a value of "PrinterName (from WORKSTATION) in session 5"
for /f "tokens=1 delims=," %%i in ('"echo %DefaultPrinter%"') do set OldPrinterString=%%i

REM :: create variable %PrinterName% with a value of "PrinterName"
for /f "tokens=1 delims=(" %%k in ('"echo %DefaultPrinter%"') do set PrinterName=%%k


REM :: Notes
REM :: using this string "DefaultPrinter = PrinterName (from WORKSTATION) in session 5,winspool,TS010"
REM :: "delims=," means that each comma is used to seperate each segment of the DefaultPrinter string into a token
REM :: "tokens=1" would return "PrinterName (from WORKSTATION) in session 5"
REM :: "tokens=2" would return "winspool"
REM :: "tokens=3" would return "TS010"
REM :: "delims= " means that each space is used to seperate each segment of the DefaultPrinter string into a token
REM :: "tokens=1" would return "PrinterName"
REM :: "tokens=2" would return "(from"
REM :: "tokens=3" would return "WORKSTATION)"


REM :: take the original printer name ("PrinterName (from WORKSTATION) in session 5") and change it to just "PrinterName"
rundll32 printui.dll,PrintUIEntry /Xs /n "%OldPrinterString%" printername "%PrinterName%"


Rem Done!
EndLocal
Goto EoF

:Error
msg %SessionName% /W Your printer was not successfully configured.  Please log off and log on again.  If you continue to receive this message, please contact the network Administrator.  (Error Code: %1)
EndLocal
Goto EoF

:EoF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top