#192464 - 2009-02-24 10:00 AM
Deleting and re-installing network printers
|
Ronnie
Fresh Scripter
Registered: 2009-02-23
Posts: 5
Loc: Denmark
|
Hi all,
I want to change the naming standard for all printers in my company. This goes for both the sharenames and printer names. The idea is that I'll do this outside normal working hours and then for a period of time update the login script so that it first checks if a network printer is installed, and if this is the case it deletes the network printer and then re-installs it with the new name. This will be done for each network printer in the company, and if the printer isn't installed on the specific pc the script will just move on to check for the next printer. However I can't get this to work properly.
I'm not sure the above can be accomplished using a batch login script, so if anybody can help me scripting this using Kix I'd be very thankful.
This is an example of the script for a printer with old printer name OKI C5600 and sharename OKIC5600 and new printer name Herlev - Stuen - ANBL - Oki C5600 and sharename ANBLOkiC5600:
if not exist \\fs\OKIC5600 goto ok_OKIC5600 rundll32 printui.dll,PrintUIEntry /dn /n\\fs\OKIC5600 /j"OKI C5600" rundll32 printui.dll,PrintUIEntry /in /n\\fs\ANBLOkiC5600 /j"Herlev - Stuen - ANBL - Oki C5600" :ok_OKIC5600
Can anybody tell me why this isn't working? I think the problem is that "if not exist \\fs\OKIC5600 goto ok_OKIC5600" looks for a printer with the sharename OKIC5600 on the print server named fs, and this no longer exists since I've changed the sharename to ANBLOkiC5600, and because this no longer exists on the print server it goes to ":ok_OKIC5600".
So the challenge is to change the \\fs\OKIC5600 part to instead search for the network printer on the local pc, but how can I do this with Kix so it works for all pc's in the domain?
Thanks in advance, Ronnie
|
Top
|
|
|
|
#192474 - 2009-02-24 03:33 PM
Re: Deleting and re-installing network printers
[Re: Lonkero]
|
Ronnie
Fresh Scripter
Registered: 2009-02-23
Posts: 5
Loc: Denmark
|
Thanks for the advice. I've been looking around and this seems to be closest post to what I want to achieve http://www.kixtart.org/forums/ubbthreads...rue#Post187369. But it's for changing print server and not printer names, so I hope someone can help me modifying the code?
Thanks in advance, Ronnie
|
Top
|
|
|
|
#192560 - 2009-02-26 01:29 PM
Re: Deleting and re-installing network printers
[Re: Mart]
|
Ronnie
Fresh Scripter
Registered: 2009-02-23
Posts: 5
Loc: Denmark
|
Hi and thanks for your help so far. However I'm quite new with this stuff and I really don't know how to modify the code to make it match my requirements. As far as I can see the code is for changing printserver, which isn't what I'm doing. I'm hoping tha someone can come up with a code that can help me here?
Thanks in advance, Ronnie
|
Top
|
|
|
|
#192565 - 2009-02-26 02:14 PM
Re: Deleting and re-installing network printers
[Re: Mart]
|
Ronnie
Fresh Scripter
Registered: 2009-02-23
Posts: 5
Loc: Denmark
|
Hi and sorry about that. Somehow I missed your question.
You're right that I don't want to change the printer names in the script. I'll be doing this directly on the print server prior to updating the login script with the Kix code.
Basically what I want is for the script to check the pc for any network printers installed with the old names, and if it detects any it should delete the printer and install the same printer with the new name. However only previously installed printers should be re-installed so just deleting all printers and then instaling all avilable network printers will not work. Keeping the default printer would also be a good thing.
Most of your code makes sense with the comments you've put in, but what is confusing me is that you specify a old and a new server in your code while my print server is named FS and this will not change only printer names and share names will.
Thanks again, Ronnie
Edited by Ronnie (2009-02-26 02:53 PM)
|
Top
|
|
|
|
#192632 - 2009-02-27 08:36 AM
Re: Deleting and re-installing network printers
[Re: Gargoyle]
|
Ronnie
Fresh Scripter
Registered: 2009-02-23
Posts: 5
Loc: Denmark
|
Hi Gargoyle,
Ok - that makes sense, but how can I call the map file from the Kix code?
Regards, Ronnie
Edited by Ronnie (2009-02-27 11:14 AM)
|
Top
|
|
|
|
#192740 - 2009-03-06 09:30 PM
Re: Deleting and re-installing network printers
[Re: Lonkero]
|
ffangus
Just in Town
Registered: 2009-02-09
Posts: 1
Loc: United States
|
I am looking for something similar, but going to the next level. I am attempting to move off an old print server and move it to a new print server with a new name. The new server has the same IP's but a different share and printer name.
|
Top
|
|
|
|
#194341 - 2009-06-22 09:35 PM
Re: Deleting and re-installing network printers
[Re: Lonkero]
|
dataspike
Getting the hang of it
Registered: 2005-03-09
Posts: 89
Loc: San Diego, CA
|
I ran in to this same issue/question, so I thought I'd share my results.
These functions allow me to enumerate the printers installed, and change the printer name (ONLY).
ChangePrinterName('OldName','NewName')
Function ChangePrinterName($OldPrinterName, $NewPrinterName)
$printers = arrenumkey('HKCU\Printers\Connections')
For Each $printer in $printers
If InStr($printer,$OldPrinterName)
$printer = Split($printer,',')
$old = '\\' + $printer[2] + '\' + $printer[3]
$new = '\\' + $printer[2] + '\' + $NewPrinterName
$rc = AddPrinterConnection($new)
If Not @error
If Primapstate($old) = 2
$rc = SetDefaultPrinter($new)
EndIf
$rc = DelPrinterConnection($old)
EndIf
EndIf
Next
EndFunction
Function PriMapState($_Pri)
If Len(ReadValue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Devices",$_Pri))
If Split(ReadValue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),",")[0] = $_Pri
$PriMapState = 2
Else
$PriMapState = 1
EndIf
EndIf
EndFunction
Function arrenumkey($regkey)
Dim $Keylist, $c
If Not KeyExist($regkey)
Exit 87
EndIf
Do
$Key = $Key+'|'+EnumKey($regkey,$c)
$c = $c + 1
Until @error
$arrenumkey = Split(SubStr($Key,2,Len($Key)-2),'|')
EndFunction
I am sure it could be configured very easily to change server name as well.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 323 anonymous users online.
|
|
|