#42683 - 2003-07-09 08:07 PM
printer installation in Win 98
|
Mystic Mike
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1607 anonymous users online.
|
|
|