#28758 - 2002-09-11 09:02 AM
Re: Win9x and Printers
|
pommie
Fresh Scripter
Registered: 2002-02-01
Posts: 27
|
Guys, The reading of the printer variables for all OS works fine. The deleteing and re-mapping of printers for NT4 and W2K work fine. The adding off printers for Win9x works OK using Sendkeys, although I dont like it!
I dont want to use sendkey to delete the Win9x printers first also, otherwise the risk of getting stuck in a loop is too high. Ive posted the scipt below (which is basically what Kent pointed out).
Willing to dontate a kidney to anyone who can help me out with this.
; This script checks for the existence of a printer ; For NT & W2K It then disconnects and re-maps the printer ; For Windows 95 or Windows 98 is duplicates the printer mapping (this needs to be resolved)
break on if @inwin = 1 $localkey = "HKEY_CURRENT_USER\Printers\Connections" $sep = "," else
$localkey = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\Print\Printers" $sep = "\" endif $Index = 0
:Loop1 if @inwin = 1
$KeyName = ENUMKEY($localkey, $Index) else $PRINTER=ENUMKEY ($localkey, $INDEX) $PORT=ENUMVALUE ("$localkey\$printer",5) $KeyName=READVALUE ("$localkey\$printer","PORT") endif
; This section calculates the servername and sharename ; If @ERROR = 0
$lenkey = len($keyname) $keyname = substr($keyname,3,$lenkey - 2) $comma = instr($keyname,$sep) $servername = substr($keyname,1,$comma-1) $Printer = substr($keyname,$comma+1,$lenkey - $comma - 1)
; This section deletes and re-maps the printer for NT and W2K ; if @inwin = 1 ? ".......Please wait re-mapping printer connections...." ;The Del and Add Printer connection function is only available on NT
If DelPrinterConnection ("\\$servername\$printer") = 0 ? "Deleted printer connection to \\$servername\$printer ..." Endif
If ADDPRINTERCONNECTION ("\\$servername\$printer") = 0 ? "Added printer connection to $servername\$printer ...." else ? "Error = @error" Endif else
; This section adds the printer for Win95 and Win98
$RC=delprinterconnection ("")
RUN "rundll32.exe shell32.dll,SHHelpShortcuts_RunDLL AddPrinter" ? "Please wait" sleep 1 sendkeys("{ENTER}") sendkeys("~N") sendkeys("{ENTER}") sendkeys("~P") sendkeys("\\$servername\$printer") sendkeys("~N") sendkeys("{ENTER}") sleep 1 sendkeys("$printer") sendkeys("~N") sendkeys("{ENTER}") sleep 1 sendkeys("~N") sendkeys("{ENTER}") sleep 1 sendkeys("~N") sendkeys("{ENTER}")
endif
$Index = $Index + 1 goto loop1
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 809 anonymous users online.
|
|
|