#167685 - 2006-09-15 11:30 AM
Rename Printers
|
Nazeedah
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
|
|
|
|
#167687 - 2006-09-18 11:04 AM
Re: Rename Printers
|
Nazeedah
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
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
|
|
|
|
#167690 - 2006-09-18 02:00 PM
Re: Rename Printers
|
Nazeedah
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
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
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
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
|
|
|
|
#167695 - 2006-09-20 07:14 AM
Re: Rename Printers
|
Nazeedah
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
|
|
|
|
#167697 - 2006-09-20 09:03 AM
Re: Rename Printers
|
Witto
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
|
|
|
|
#167699 - 2006-09-21 07:50 AM
Re: Rename Printers
|
Nazeedah
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
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
|
|
|
|
#167703 - 2006-09-21 04:58 PM
Re: Rename Printers
|
Witto
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
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2141 anonymous users online.
|
|
|