Page 1 of 1 1
Topic Options
#42683 - 2003-07-09 08:07 PM printer installation in Win 98
Mystic Mike Offline
Fresh Scripter

Registered: 2002-03-13
Posts: 14
Loc: El Toro, CA
I've read all the posts about installing a printer on Win 98 machines and understand that most all of you think it shouldn't be done in the logon script because of the driver installation. That being said, I've got the sendkeys method working and would like to try to use it to move the printer installations from one server to another. I'll post the script that I have working below for everyone (I found it here and just adjusted it.). Two questions for the experts- is there ANY way that you know of to delete the existing printer installation after the printer is moved to the new server? In order to do more than one printer, I'll just have to copy and paste the same script multiple times, changing the $newserver/printer and $oldserver/printer variables? Maybe a loop through multiple variables? Any suggestions are appreciated.

-I didn't look into con2prt, 'cause I've got this working (so far).

code:
;  This script checks for the existence of a printer  
; if the printer exists then in installs a new printer

break on
$localkey = ""
$oldserver = "Old_server"
$oldprinter = "HPLJ5K"
$newserver = "New_server"
$newprinter = "HPLJ5000"
? "Start"
if @inwin = 1
$localkey = "HKEY_CURRENT_USER\Printers\Connections"
$sep = ","
else
? "First if - setting key"
$localkey =
"HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\Print\Printers"
$sep = "\"
endif
? "Looking for printer $oldprinter on $oldserver"
? "To Replace with $newprinter on $newserver" ?
$found1 = 0
$found2 = 0
$found3 = 0
$Index = 0
$index2 = 0
:Loop1
if @inwin = 1
$KeyName = ENUMKEY($localkey, $Index)
else
? "second if - enum printer"
$PRINTER=ENUMKEY ($localkey,$INDEX)
;$PORT=ENUMVALUE ("$localkey\$PRINTER",5)
$KeyName=READVALUE ("$localkey\$PRINTER","PORT")
endif

If @ERROR = 0
? ;"Name found: $KeyName"
$lenkey = len($keyname)
$keyname = substr($keyname,3,$lenkey - 2)
" $keyname"
$comma = instr($keyname,$sep)
$servername = substr($keyname,1,$comma-1)
$Printer = substr($keyname,$comma+1,$lenkey - $comma - 1)
" Server = $Servername, Printer = $printer"
if $printer = $oldprinter
$found1 = 1
endif
if $printer = $newprinter
$found2 = 1
endif
$Index = $Index + 1

goto Loop1
Endif
if $found1 = 1
? "Printer $oldprinter Found"
if $found2 = 1
? "Printer $newprinter already exists"
endif
endif

if $found1 = 1 and $found2 = 0
if @inwin = 1
? ".......Please wait..."
If ADDPRINTERCONNECTION ("\\$newserver\$newprinter") = 0
? "Added printer connection to \\$newserver\$newprinter ...."
DelPrinterConnection("\\$oldserver\$oldprinter")
SetDefaultPrinter("\\$newserver\$newprinter")
else
? "Error = @error"
Endif
else
RUN "rundll32.exe shell32.dll,SHHelpShortcuts_RunDLL AddPrinter"
? "Please wait"
sleep 1
sendkeys("{ENTER}")
sendkeys("~N")
sendkeys("{ENTER}")
sendkeys("~P")
sendkeys("\\$newserver\$newprinter")
sendkeys("~N")
sendkeys("{ENTER}")
sleep 1
;sendkeys("$newprinter")
sendkeys("~N")
sendkeys("{ENTER}")
sleep 1
sendkeys("$newprinter")
sendkeys("{Tab}")
sendkeys("{UP}")
sendkeys("~N")
sendkeys("{ENTER}")
sendkeys("{DOWN}")
sendkeys("{ENTER}")
sleep 1
? "Checking Printer..."
endif

? "Paused" ;Just to make sure it's running right
;get $c

_________________________
Thanks everyone, Mike

Top
#42684 - 2003-07-09 08:11 PM Re: printer installation in Win 98
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
you would need to look at the registry for dublicate printers...
you might want to even control them with ini-file.
or as I did, have all printers replicated to all servers during night time and thus, once connecting to another server, you know directly from registry data if the same printer is mapped on multiple servers and remove the rest.
_________________________
!

download KiXnet

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 1110 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.054 seconds in which 0.026 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