Page 1 of 4 1234>
Topic Options
#167685 - 2006-09-15 11:30 AM Rename Printers
Nazeedah Offline
Fresh Scripter

Registered: 2006-09-15
Posts: 20
Hello,
I have a small problem but urgent one.i have to rename printers from citrix. means that when i have my printers auto created when starting citrix it's too long and i want to rename.I get the code kiXtart but don't know how to implement it.Please do Help me
Regards and Thanks a lot
Nazeedah

Top
#167686 - 2006-09-15 05:47 PM Re: Rename Printers
therob Offline
Starting to like KiXtart

Registered: 2005-05-19
Posts: 150
Loc: Frankfurt/M., Germany
Take a look at this topic:
Citrix.com: Rename Auto-Created Printers Script

If you dont know how/when to start the script, there are a few possibilities:

- if you uncheck the option "dont wait for printer" in the publishing-options, citrix creates Printers before running the logon-script, so you could place the rename-code in a logonscript. This would be the best place. But be aware unchecking this option can slow down the application start, if someone has a lot of printers or has a network printer mapped, which is unavailable during the app-start.

- if there is just special application which needs shorter printer names you could change the citrix-publishing. For this you would place a script in the CMC publishing-preferences/commandline, that first renames your printers and then starts the application.

cu, therob
_________________________
Eternity is a long time, especially towards the end. - W.Allan

Top
#167687 - 2006-09-18 11:04 AM Re: Rename Printers
Nazeedah Offline
Fresh Scripter

Registered: 2006-09-15
Posts: 20
Hello
Thank you very much for your quick response. But the problem is that the server is Windows 2000 server. and its not recognzing the Rename Printer
Here is the script that i run
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer")

For Each objPrinter in colPrinters
If Left(objPrinter.DeviceID,22) = "Client\pailles_dom-nns" Then
Wscript.Echo objPrinter.DeviceID
Wscript.Echo Mid(objPrinter.DeviceID, InStrRev(objPrinter.DeviceID, "\") + 1)
varprint= Mid(objPrinter.DeviceID, InStrRev(objPrinter.DeviceID, "\") + 1)
objPrinter.RenamePrinter("hp LaserJet 1320 PCL 5e")
END IF
Next


Its working fine on XP but on Windows 2000 Server i am having the error:
C:\script\printerrename1.vbs(14, 5) Microsoft VBScript runtime error: Object
doesn't support this property or method: 'objPrinter.RenamePrinter'.

i have got another script from the KiXtart site but don;t know how to implement on the machine or how to test it.If you would like to have a look at the script KiXtat, i can send you

PLease do help me.I really need it

Thanks a lot in advance

Nazeedah

Top
#167688 - 2006-09-18 12:15 PM Re: Rename Printers
therob Offline
Starting to like KiXtart

Registered: 2005-05-19
Posts: 150
Loc: Frankfurt/M., Germany
im not that much into vbs, but if the object-method 'renamePrinter" doesnt work on W2k, you won't have any luck with kix either, as its uses the same classes.

http://www.microsoft.com/technet/scriptcenter/...:
"Well, if your printer is connected to a Windows 2000 or Windows NT 4.0 print server we have bad news for you: you can’t rename a printer using a script, at least not using the technologies included in the operating system. (There might, or might not, be third-party tools that enable you to do this on those older versions of Windows.) If your printer is connected to a computer running Windows XP or Windows Server 2003, however, the news is much better. That’s because the Win32_Printer class – which was extensively overhauled for Windows XP and Windows Server 2003 – includes a new method named RenamePrinter, a method which definitely lives up to its name...."

I know this doesn't help much, but maybe take this as a chance to upgrade your servers. Another good argument for this would be that Microsoft ceased official support for Windows 2000 last year.

EDIT: : Wait, maybe i found something. Take a look at this, it uses a rundll32-call to rename a printer:
http://terminal.servebeer.com/php/renameprinter.php

cu, rob
_________________________
Eternity is a long time, especially towards the end. - W.Allan

Top
#167689 - 2006-09-18 12:52 PM Re: Rename Printers
therob Offline
Starting to like KiXtart

Registered: 2005-05-19
Posts: 150
Loc: Frankfurt/M., Germany
Just tried it, it seems to work fine. The keyline is this:
Code:
  
rundll32 printui.dll,PrintUIEntry /Xs /n "OLDprintername" printername "NEWprintername"



So, i think you just need to read the printernames from:
"HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Devices" ,
check them for lenght and rename them if necessary. Should be no problem to do that in kix with enumkey() and len().
_________________________
Eternity is a long time, especially towards the end. - W.Allan

Top
#167690 - 2006-09-18 02:00 PM Re: Rename Printers
Nazeedah Offline
Fresh Scripter

Registered: 2006-09-15
Posts: 20
Thank you very much for your quick and precious help.

i have execute it, at first i was getting an error at line :

rundll32 printui.dll,PrintUIEntry /Xs /n "%OldPrinterString%" printername "%PrinterString%"

then i modify it to:

rundll32 printui.dll,PrintUIEntry /Xs /n "%OldPrinterString%" printername "testprinter"

then its work

what i would like to do is to rename the existing printer for example the printer is named: Client\pailles_dom-nns\\\hfdc01pl \laserjet 1320

i would like it to be only : laserjet 1320.

how can i modify the code so that only part of it change and the new rename printer be the default printer itself.


Thanks a lot
Nazeedah

Top
#167691 - 2006-09-18 03:44 PM Re: Rename Printers
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Code:

Dim $PrinterName, $NewPrinterName
$PrinterName = "Client\pailles_dom-nns\\\hfdc01pl \laserjet 1320"
$NewPrinterName = Split($PrinterName,"\")[Ubound(Split($PrinterName,"\"))]
? $NewPrinterName


I just copied and pasted the printername like you wrote it. Please revise that name. There is IMHO an error in it. Shouldn't it read:
"\\Client\pailles_dom-nns\hfdc01pl \laserjet 1320" ?


Edited by Witto (2006-09-19 09:51 AM)

Top
#167692 - 2006-09-19 08:11 AM Re: Rename Printers
Nazeedah Offline
Fresh Scripter

Registered: 2006-09-15
Posts: 20
Hello
Thank you for your answers

this the code that i am actually running. I have done some changes but can you please check since i am having an error.


Rem Set the local variables
SetLocal

Rem Wait about 15 seconds to let the terminal server map the printer...
Sleep 15

Rem Reads the default printer from the registry
"%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)
/**here i have have done some changes taht is i add this part so as to rename the printer**/
Dim $NewPrinterName

$NewPrinterName = Split($PrinterName,"\")[Ubound(Split($PrinterName,"\"))]
? $NewPrinterName
/*****changes end***/


Rem 2000 :: DefaultPrinter = HP DeskJet 820CSe on oz/TINMAN/Session 1,winspool,TS001
for /f "tokens=1 delims=," %%i in ('"echo %DefaultPrinter%"') do set OldPrinterString=%%i
for /f "tokens=1 delims=/" %%j in ('"echo %DefaultPrinter%"') do set PrinterString=%%j

Rem 2000 :: PrinterString = HP DeskJet 820Cse on oz/%clientname%/session 1
Rem Attempt to rename the printer...
rundll32 printui.dll,PrintUIEntry /Xs /n "%OldPrinterString%" printername "%NewPrinterName%"

/****can you please check the line above since the error i receive is from this line**/

Rem Done!
EndLocal
Goto EoF

:Error
msg %SessionName% /W Your printers were not successfully renamed. Please notify an administrator. (Error Code: %1)
EndLocal
Goto EoF

:EoF


PLease help me quickly. i really need it.

Let me know if you need additional information
Thank you a Lot
Nazeedah

Top
#167693 - 2006-09-19 09:08 AM Re: Rename Printers
Nazeedah Offline
Fresh Scripter

Registered: 2006-09-15
Posts: 20
Hello
I think taht this code should work, after lots of reading I have run this script below:


Rem Set the local variables
SetLocal

Rem Wait about 15 seconds to let the terminal server map the printer...
Sleep 15

Rem Reads the default printer from the registry
"%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 2000 :: DefaultPrinter = HP DeskJet 820CSe on oz/TINMAN/Session 1,winspool,TS001
for /f "tokens=1 delims=," %%i in ('"echo %DefaultPrinter%"') do set OldPrinterString=%%i
for /f "tokens=1 delims=/" %%j in ('"echo %DefaultPrinter%"') do set PrinterString=%%j

Rem 2000 :: PrinterString = HP DeskJet 820Cse on oz/%clientname%/session 1
Rem Attempt to rename the printer...
rundll32 printui.dll,PrintUIEntry /Xs /n "%OldPrinterString%" printername "%PrinterString%"

Rem Done!
EndLocal
Goto EoF

:Error
msg %SessionName% /W Your printers were not successfully renamed. Please notify an administrator. (Error Code: %1)
EndLocal
Goto EoF

:EoF


but i am having an error at the code below especially at "%PrinterString%" . i have to run this on Windows 2000 server.

rundll32 printui.dll,PrintUIEntry /Xs /n "%OldPrinterString%" printername "%PrinterString%"

Thanks a lot

Nazeedah

Top
#167694 - 2006-09-19 01:49 PM Re: Rename Printers
therob Offline
Starting to like KiXtart

Registered: 2005-05-19
Posts: 150
Loc: Frankfurt/M., Germany
Try this:

Code:
 

Break on

$Count = 0
$PRNKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices"

While @ERROR = 0
$OldPrinterName = EnumValue ($PRNKey,$Count)
If @ERROR Exit 0 EndIf

$NewPrinterName = Split($OldPrinterName,"\")[Ubound(Split($OldPrinterName,"\"))]

If $NewPrinterName <> $OldPrinterName
Run '%COMSPEC% /c rundll32 printui.dll,PrintUIEntry /Xs /n "$OldPrinterName" printername "$NewPrinterName"'
EndIf
$Count = $Count + 1
Loop

Exit 0




The rundll doesnt return an errorcode, so if an error occurs you'll get a pop-up.
_________________________
Eternity is a long time, especially towards the end. - W.Allan

Top
#167695 - 2006-09-20 07:14 AM Re: Rename Printers
Nazeedah Offline
Fresh Scripter

Registered: 2006-09-15
Posts: 20
Hello
Thx a lot for the help.
I have try the above code but the printer name haven't changed.
I have two printers. I have copy the code same as it is nad make it a batch file and execute it.
i have to change the printer whose name start with client e.g :Client\pailles_dom-nns#\\\HWFDC01PL\hp LaserJet 1320 PCL 5e and rename it to last part only i.e hp LaserJet 1320 PCL 5e.

Top
#167696 - 2006-09-20 08:02 AM Re: Rename Printers
therob Offline
Starting to like KiXtart

Registered: 2005-05-19
Posts: 150
Loc: Frankfurt/M., Germany
Well, i tried it, it should work. There must be another reason why it doesn't when you execute it. Please describe *exactly* how you tested it.
Top
#167697 - 2006-09-20 09:03 AM Re: Rename Printers
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Quote:


Client\pailles_dom-nns#\\\HWFDC01PL\hp LaserJet 1320




I still do not understand that name, shouldn't that be
\\Client\pailles_dom-nns#\HWFDC01PL\hp LaserJet 1320

Top
#167698 - 2006-09-20 09:57 AM Re: Rename Printers
therob Offline
Starting to like KiXtart

Registered: 2005-05-19
Posts: 150
Loc: Frankfurt/M., Germany
Quote:


I still do not understand that name, shouldn't that be
\\Client\pailles_dom-nns#\HWFDC01PL\hp LaserJet 1320




Nah, thats ok. Citrix (before PS4) does that, e.g. when connecting a printer shared by another client that is mapped to the client. The syntax is "client\[clientname]\\\[name of client with printer]\[printername]".

Btw. Nazeedah, which Citrix version do you run?
_________________________
Eternity is a long time, especially towards the end. - W.Allan

Top
#167699 - 2006-09-21 07:50 AM Re: Rename Printers
Nazeedah Offline
Fresh Scripter

Registered: 2006-09-15
Posts: 20
Thx for your quick reply.
You are right its only "client\.." and not"\\client"
i have a Citrix Metaframe XP Server for Windows,with features Release 3

I am not sure wherther i have answer it correct.
Please do give me a solution of how to rename the printer. its Urgent.
Thanks a lot

Nazeedah

Top
#167700 - 2006-09-21 12:18 PM Re: Rename Printers
Nazeedah Offline
Fresh Scripter

Registered: 2006-09-15
Posts: 20
Hello
I have run the script below and its works well but i would like it to return the printer name that is "Laserjet 1320" but instead its returning "client".i want it to return the last part of the printer.and most important thing is that when the next time the user login i don't want it to have two printer one that has just been created and one that has been renamed in the previous login.

Code:
 


Rem Set the local variables
SetLocal

Rem Wait about 15 seconds to let the terminal server map the printer...
Sleep 15

Rem Reads the default printer from the registry
"%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 2000 :: DefaultPrinter = HP DeskJet 820CSe on oz/TINMAN/Session 1,winspool,TS001

for /f "tokens=1 delims=," %%i in ('"echo %DefaultPrinter%"') do set OldPrinterString=%%i

for /f "tokens=1 delims=\" %%j in ('"echo %DefaultPrinter%"') do set PrinterString=%%j

Rem 2000 :: PrinterString = HP DeskJet 820Cse on oz/%clientname%/session 1
Rem Attempt to rename the printer...

rundll32 printui.dll,PrintUIEntry /Xs /n "%OldPrinterString%" printername "%PrinterString%"

Rem Done!
EndLocal
Goto EoF

:Error
msg %SessionName% /W Your printers were not successfully renamed. Please notify an administrator. (Error Code: %1)
EndLocal
Goto EoF

:EoF


PLease do help me as it is urgent

Thanks in advance
Nazeedah

Top
#167701 - 2006-09-21 12:53 PM Re: Rename Printers
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
You are still BATCH scripting. If you want to discuss this, I would think this belongs to General Discussions. therob gave you an example how to do this in KiX.
Top
#167702 - 2006-09-21 04:08 PM Re: Rename Printers
therob Offline
Starting to like KiXtart

Registered: 2005-05-19
Posts: 150
Loc: Frankfurt/M., Germany
Witto is right, i cant help you with the batch neither. I did translate the important parts of the batch to kix for you. I tested it, it works. If you tell us exactly how you tested the kix-code when it failed, we can help you find the problem.
As a hint: dont try the code on a local workstation with mapped network printers! If you do that, it tries to change the printername on the printserver or the client which shared the printer. It only works correctly with *local* printers on a client (for testing purposes) or with printers *in* a citrix session.

Apart from that, i think it might be helpful for you to read a bit around the whole citrix printing process.

Top
#167703 - 2006-09-21 04:58 PM Re: Rename Printers
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
If I understand well, Nazeedah only wants to rename printers in a citrix terminal session. Maybe a check can be added to therob's code to verify if it is really about a citrix terminal session...
Code:

Dim $ClientName
$ClientName = ExpandEnvironmentVars(%clientname%)
;? "ClientName Environment Variable = " + $ClientName
If $ClientName
;? "Citrix session"
;KiX Code here to rename printers
;Else
;? "No Citrix session"
EndIf


Top
#167704 - 2006-09-21 07:40 PM Re: Rename Printers
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
@TsSession
This macro will return a 1 if KiXtart is running in a Terminal Server session

Top
Page 1 of 4 1234>


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2141 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.089 seconds in which 0.04 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org