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)