Page 1 of 1 1
Topic Options
#9458 - 2001-06-12 09:59 PM Adding and removing printers
Anonymous
Unregistered


I know most of you have been involved in printer and Kixtart in one way or another. I did a search on the site and fould a ton of stuff.
Does anyone have anything that works for this situation.

I have one master print server which I am slowly move all the users to.

On each of my domains, by the way I have 13 domains and all of them have printers on them.

So what I was trying to get done was somehow verifing what printers are installed at the workstations then compare it to a pre defined list and redirect it to the proper print que. So does anybody have any Ideas


Top
#9459 - 2001-06-13 12:01 AM Re: Adding and removing printers
Anonymous
Unregistered


We are in the progress of moving from Netware printers to NT. SO I created a script that detects if a Netware printer is installed by searching for the text "PHNIM" in a registry area, and then deleting that key. Here's the program: (note that I had to do the DO UNTIL statement twice as for some reason there would sometime be one printer still remaining, this fixed it.
Also note that the lines in this example have been cropped to the next line, so hope you understand that. Cheers

break on
setconsole("hide")
$key="HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\Print\Printers"
$key1="HKEY_LOCAL_MACHINE\System\CurrentControlSet"
$key2="$key1\control\Print\Printers\"
IF EXIST("C:\novell.txt")=0
IF (existkey($key) = 0)
$index=0
DO
$icode=ENUMKEY($key, $index)
IF (len($icode) <> 0)
$x = instr($icode, ",,PHNIM")
IF $x = 1
$all = $key2+$icode
$r1 = delkey("$all\Dsdriver")
$r2 = delkey("$all\DsSpooler")
$r3 = delkey("$all\PnPData")
$r4 = delkey("$all\PrinterDriverData")
$r5 = delkey("$all")
ENDIF
ENDIF
$index=$index+1
UNTIL (len($icode) = 0)
$index=0
DO
$icode=ENUMKEY($key, $index)
IF (len($icode) <> 0)
$x = instr($icode, ",,PHNIM")
IF $x = 1
$all = $key2+$icode
$r1 = delkey("$all\Dsdriver")
$r2 = delkey("$all\DsSpooler")
$r3 = delkey("$all\PnPData")
$r4 = delkey("$all\PrinterDriverData")
$r5 = delkey("$all")
ENDIF
ENDIF
$index=$index+1
UNTIL (len($icode) = 0)
ENDIF
shell "%comspec% /e:1024 /c k:\aj\print\netsvc" +" spooler"+" \\" +@wksta+" /stop"
sleep 6
shell "%comspec% /e:1024 /c k:\aj\print\netsvc" +" spooler"+" \\" +@wksta+" /start"
sleep 3
copy "k:\aj\print\novell.txt" "c:\novell.txt"
ENDIF

Top
#9460 - 2001-06-13 04:02 PM Re: Adding and removing printers
Anonymous
Unregistered


I found this script and it seems to work fine on NT but I haven't tested it on any other systems. The problem I am having is I need some way of creating a list of printers that are installed on the clients machine upon logon, Once the printers are discovered, create a file installed.dat and then I need it to fine the new printer in the print.dat file that I created that is the match to the old one then delete the old printer and create the new. The problem with this script is that it locates by group
and that doesn't work in my case.

I was thinking of the print.dat file to be like this, that way when the old one was detected the new printer would be associated with it on the same readline command.
But how would I be able to locate the old printer the the dat file and then read that line so I can set my varibles.

\\server\printer,\\server\newprinter


? @USERID + ": Please wait while your printers are being added...."
sleep 5
cls
If ADDPRINTERCONNECTION ("$printeradd") = 0
? @USERID + " Your New Printers Were Added...."
SETDEFAULTPRINTER ("$printerdef")
delprinterconnection ("$printerdel")
ELSE
? @USERID + ": There was an error adding your Printers. Contact Help Desk x1111!"
?
?
?
Endif

Top
#9461 - 2001-06-13 04:28 PM Re: Adding and removing printers
Anonymous
Unregistered


Gary,
I dont know whether this fits the bill, but this is what we use in our logon scripts to search and destroy existing printers, (we then re-add them based upon group memberships)

$KEY = "HKEY_CURRENT_USER\Printers\Connections"
$DEL_PRT_ERR_CNT = 0


$SubKey = EnumKey( $KEY , 0 )
WHILE @ERROR = 0 AND $DEL_PRT_ERR_CNT = 0
$wrk = SUBSTR($Subkey,3,30)
$comma = instr($wrk,",")
$svrend = $comma - 1
$prtsrt = $comma + 1
$svr = RTRIM(SUBSTR($wrk,1,$svrend))
$prt = RTRIM(SUBSTR($wrk,$prtsrt,20))
$uncname = "\\"+$svr+"\"+$prt
? "unc name is >>"+$uncname+"<<"
$DEL_RC = delprinterconnection($uncname)
If $DEL_RC <> 0
$DEL_PRT_ERR_CNT = $DEL_PRT_ERR_CNT + 1
endif
? "return code from delpc is "+$DEL_RC+" error text is "+@SERROR+"."
$SubKey = EnumKey( $KEY , 0)
LOOP

I have hacked this out of a larger script, but I cant see any uninitialised variables etc (but I have been wrong before).

I hope this helps.
PS: the rest of my script then checks on group memberships and add printers - but this add is done by checing a short list of servers for the presence of a printer share - this bit of code might be useful to you aswell I guess - if it is say - Ill append it.

Mark

Top
#9462 - 2001-06-14 06:33 AM Re: Adding and removing printers
Anonymous
Unregistered


Thanks for the help I getting closer, Do you know if there is anyway to generate a file of printers installed on the workstation during login.
Top
#9463 - 2001-06-14 10:20 AM Re: Adding and removing printers
Anonymous
Unregistered


Gary,
Ok what about this...

BREAK ON
$Key = "HKEY_CURRENT_USER\Printers\Connections"
$prt_log = "C:\Printers.txt"

DEL $prt_log

$SubKey = EnumKey( $Key , 0 )
$INDEX = 0
WHILE @ERROR = 0
$wrk = SUBSTR($Subkey,3,30)
$comma = instr($wrk,",")
$svrend = $comma - 1
$prtsrt = $comma + 1
$svr = RTRIM(SUBSTR($wrk,1,$svrend))
$prt = RTRIM(SUBSTR($wrk,$prtsrt,20))
$uncname = "\\"+$svr+"\"+$prt
$rc = open(1,$prt_log,5)
$rc = writeline(1,$uncname+chr(13)+chr(10))
$rc = close(1)
$INDEX = $INDEX + 1
$SubKey = EnumKey( $Key ,$INDEX)
LOOP
$Total_printers = $INDEX - 1
? "Written "+$Total_printers+" entries to "+$prt_log

It works for my environment where I have 100% printer connections (no local printers) and I am on 2000 (although I am certain it runs on NT aswell)

Is that what you wanted ?
Mark

Top
#9464 - 2001-06-14 06:09 PM Re: Adding and removing printers
Anonymous
Unregistered


To Cool Thanks a bunch it works great and gets me the file I needed to generate so I can start the second part of the program You said this dosn't work on win9x? is it just a different Key
Top
#9465 - 2001-06-14 06:20 PM Re: Adding and removing printers
Anonymous
Unregistered


Gary,
I am sure I remember it having some problem under 95 (we have a different way of printing in 95 so I never pursued it), but it would have just been an issue of the Registry key - the rest of the code would work just fine.

Mark

Top
Page 1 of 1 1


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

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.063 seconds in which 0.034 seconds were spent on a total of 12 queries. Zlib compression enabled.

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