Home : Shorten autogenerated printer names (that are too long) in Citrix / Terminal Services
Q11387 - HOWTO: Shorten autogenerated printer names (that are too long) in Citrix / Terminal Services

BACKGROUND :

Often times in Citrix or Terminal Services environments, the autogenerated printer names are too long for certain applications.   For example, the Hach WIMS Graph Pac can only support 32 character printer names (See KB Q10186).  
For example "HP Laserjet 2100 TN on CITRIXSERVERA (from LT037) on session 21" printer name is way too long for an application that only supports 32 character long printer names. 

FIX :

You'll have to create a script that uses Windows Management Interface to shorten the autogenerated printer names.
This script will then need to be added into scheduled tasks in Windows, and setup to run with Administrator priviledges once every minute.

Create a similar script to suit your need:

Use Notepad and create a file with a .vbs extenstion (i.e. RenamePrinters.vbs) and paste the following code:

on error Resume Next
lngMaxCharsAllowed = 32
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems =  objWMIService.ExecQuery("Select * from Win32_Printer",,48)
For Each objItem in colItems
    if len(objItem.Name) > lngMaxCharsAllowed then   
     objItem.RenamePrinter(left(objItem.Name, lngMaxCharsAllowed))
    end if
Next

You can test the script file by simply double clicking on the file (i.e. the RenamePrinters.vbs file). 

 

It is expected that you understand the general theories of Windows Scripting and the use of WMI Moniker.
For more information, follow this article's links.

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
Using WMI object paths
WMI scripting primer
Scripting Concepts and Technologies for System Administration
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.
Created on 7/30/2008 9:47 AM.
Last Modified on 11/29/2011 1:20 PM.
Last Modified by Scott Dorner.
Suggested by Tom Melosi
Skill Level: Advanced.
Article has been viewed 10100 times.
Rated 4 out of 10 based on 11 votes.
Print Article
Email Article