#37350 - 2003-03-05 08:50 PM
Prevent special printers from being deleted
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
I'm going to be adding new printers to user workstations when they run a script.
My thought was to originally remove all printers, mark the registry I've already done the remove all, then add the printer/s the user wants.
One issue I'm having is... How do I prevent items from being deleted, such as:
WinFax Pro Adobe Acrobat Printer PDF Broderbund PDF Creator AutoCAD X-Ref etc...
I want to remove all the printer connections,(except for special drivers that are not real printers) and add in the new printers that are now on a new server and a new path.
Here is what I'm currently doing to add the printer, currently no removal code.... for old printers.
Break on DIM $x IF @INWIN=1 IF INGROUP("\\@WKSTA\Power Users") OR INGROUP("\\@WKSTA\Administrators") AddNetworkPrinter($Server, $PrinterName) ELSE $x=MessageBox("The Network logon process has attempted to update your printers to the new print servers, however, it appears that you may not have sufficient rights to add a printer at this time. Please contact the Helpdesk for further assistance.", "Add Printer Warning!", 16) ENDIF ENDIF
Function AddNetworkPrinter($Server, $PrinterName) Dim $Server, $PrinterName If ADDPRINTERCONNECTION("\\$Server\$PrinterName") = 0 ? "Added printer connection...$PrinterName" ? "Error level is: "+@ERROR +" "+@SERROR Endif EndFunction
[ 06. March 2003, 01:00: Message edited by: NTDOC ]
|
Top
|
|
|
|
#37351 - 2003-03-12 08:51 PM
Re: Prevent special printers from being deleted
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
I want to thank Lonkero for giving me a different perspective on viewing his UDF for the Printer change. Initially looking at his UDF
PriMapState() - Checks for existent printerconnection
I did not think it would do what I wanted it to do. After viewing what it does, and not how it does it, Lonkero showed me that it would do what I wanted it to do.
Thanks Lonkero
The task: Take 5 NT 4.0 Print Servers on an NT 4 Domain and combine them to 2 Windows 2000 Print Servers in AD. This gives all printers a new path and name. Now during logon, modify all the users printers to the new location and name without the user even being aware it was changed.
This now takes and deletes ONLY matching printers from the .INI file and then RE-ADDS back in the Same printer from the new location and name. It maintains the users Current Default printer as well, but with the new printer.
Create a .INI file with the OLD=NEW Printer translation change and put in a location where all users can get to it. Example: [PRINTMAP] \\server1\myprinter=\\NEWServer2\MyNewPrintName
Then here is the code I put together to do the task. We are not modifying Windows 9x computers, so I reduced Lonkero's UDF back down to NT only code as he originally had it.
NOTE: Edited the code and removed the check for Admin or Printer group. Appears that a network printer does not require those type of rights. Adding a local printer does. Thanks to Les for the tip.
Code:
Break on SELECT CASE @DOMAIN = "domain1" $pmap="\\server1\share\PRINTERS.INI" CASE @DOMAIN = "domain2" $pmap="\\server2\share\PRINTERS.INI" CASE 1 $pmap="\\server2\share\PRINTERS.INI" ENDSELECT IF @INWIN=1 FOR each $key in split(readprofilestring("$pmap","PRINTER_MAP",""),chr(10)) IF primapstate($key) $nul=addprinterconnection(readprofilestring("$pmap","PRINTER_MAP",$key)) IF primapstate($key)=2 $nul=SETDEFAULTPRINTER (READPROFILESTRING("$pmap","PRINTER_MAP",$key)) ENDIF $nul=delprinterconnection($key) ENDIF NEXT ENDIF
Function PriMapState($_Pri) IF len(readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices",$_Pri)) IF instr(readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),$_Pri) $PriMapState=2 ELSE $PriMapState=1 ENDIF ENDIF EndFunction
Edited by NTDOC (2005-03-23 07:30 PM)
|
Top
|
|
|
|
#37354 - 2003-03-12 11:18 PM
Re: Prevent special printers from being deleted
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
Nope... See ameneded code and note above.
I removed it already.
|
Top
|
|
|
|
#37355 - 2003-03-12 11:35 PM
Re: Prevent special printers from being deleted
|
MightyR1
MM club member
Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
|
Me confused
code:
IF primapstate($key) IF primapstate($key)=2 $nul=delprinterconnection($key) $nul=addprinterconnection(readprofilestring("$pmap","PRINTER_MAP",$key)) $nul=SETDEFAULTPRINTER (READPROFILESTRING("$pmap","PRINTER_MAP",$key)) ENDIF $nul=delprinterconnection($key) $nul=addprinterconnection(readprofilestring("$pmap","PRINTER_MAP",$key)) ENDIF
If I read this correctly it deletes the printer twice if the printer is the default one, Correct?
Should it not be:
code:
IF primapstate($key) $nul=delprinterconnection($key) $nul=addprinterconnection(readprofilestring("$pmap","PRINTER_MAP",$key)) IF primapstate($key)=2 $nul=SETDEFAULTPRINTER (READPROFILESTRING("$pmap","PRINTER_MAP",$key)) ENDIF ENDIF
_________________________
Greetz, Patrick Rutten
- We'll either find a way or make one... - Knowledge is power; knowing how to find it is more powerful... - Problems don't exist; they are challenges...
|
Top
|
|
|
|
#37360 - 2003-06-03 04:07 PM
Re: Prevent special printers from being deleted
|
Gazzalad
Fresh Scripter
Registered: 2002-03-18
Posts: 22
Loc: Germany
|
Hope you don't mind this addition..
I'm trying to migrate users printers from one server to another. All users are using XP pro connected to an NT network.
The problem I have is that all the current printers are setup as local ports pointing to the PDC. I get problems if I try to install the printers direct from the add network printer wizard (See MS Knowlegde base Q314073) and this is why we went the local port method.
Does anyone know a way of adding a printer port and migrating them over? Basically exactly what this script does for network printers.
Many thanks...
|
Top
|
|
|
|
#175304 - 2007-04-09 11:57 PM
Re: Prevent special printers from being deleted
[Re: NTDOC]
|
jojopuppyfish
Fresh Scripter
Registered: 2006-06-26
Posts: 5
|
For post 37351, it should say in the .ini file, PRINTER_MAP instead of PRINTERMAP
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 329 anonymous users online.
|
|
|