Page 1 of 1 1
Topic Options
#37350 - 2003-03-05 08:50 PM Prevent special printers from being deleted
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11556
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 Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11556
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
#37352 - 2003-03-12 09:36 PM Re: Prevent special printers from being deleted
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
Sweet... [Cool]
_________________________
We all live in a Yellow Subroutine...

Top
#37353 - 2003-03-12 11:03 PM Re: Prevent special printers from being deleted
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I don't believe the admin priv check is required though.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#37354 - 2003-03-12 11:18 PM Re: Prevent special printers from being deleted
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11556
Loc: CA
Nope... See ameneded code and note above.

I removed it already. [Big Grin]

Top
#37355 - 2003-03-12 11:35 PM Re: Prevent special printers from being deleted
MightyR1 Offline
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
#37356 - 2003-03-13 12:06 AM Re: Prevent special printers from being deleted
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22298
Loc: OK
no.
your correction will return always 0 as the state of defaulprinter check as you have already removed the old one [Razz]

I would go for:
code:
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



[ 13. March 2003, 00:51: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#37357 - 2003-03-13 12:35 AM Re: Prevent special printers from being deleted
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11556
Loc: CA
I have not tested Lonkero's code, but I do know that I have now tested my code on NT/200/XP and it has worked like a charm on EVERY system so far.

I will try to test Lonkero's code tomorrow. I have to run soon, so won't have time tonight.

Top
#37358 - 2003-03-13 12:42 AM Re: Prevent special printers from being deleted
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22298
Loc: OK
doc, indeed.
your code works.
patricks doesn't.

mine is just a shorted version of the same task with no dublicates...
well, I call primapstate() twice but no other doubles...
_________________________
!

download KiXnet

Top
#37359 - 2003-03-13 12:49 AM Re: Prevent special printers from being deleted
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11556
Loc: CA
Yes,

Confirmed... Lonks code does work.

I updated the code above. Time to run. Thanks Patrick and Lonkero

Top
#37360 - 2003-06-03 04:07 PM Re: Prevent special printers from being deleted
Gazzalad Offline
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
#37361 - 2003-06-03 06:42 PM Re: Prevent special printers from being deleted
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Gazzalad,
Please do not hijaak threads. You should start your own. Your situation is not at all related to this thread.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#175304 - 2007-04-09 11:57 PM Re: Prevent special printers from being deleted [Re: NTDOC]
jojopuppyfish Offline
Fresh Scripter

Registered: 2006-06-26
Posts: 5
For post 37351, it should say in the .ini file, PRINTER_MAP instead of PRINTERMAP
Top
Page 1 of 1 1


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

Who's Online
0 registered and 162 anonymous users online.
Newest Members
EricMyers, siddharthinfosy, raynebc, MasterNinjaSkar, hienttt
17516 Registered Users

Generated in 0.068 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

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