#28750 - 2002-09-10 04:23 AM
Win9x and Printers
|
pommie
Fresh Scripter
Registered: 2002-02-01
Posts: 27
|
Ive checked the archives and I cant find any answers about how to delete a printer connection in Win95 or 98?
I have a script that will use Send Keys to add a printer connection, so I'm pretty sure I can create one to delete the printers.
Does anyone know any better way than using send keys?
Are there any pitfalls to look out for when using send keys? i.e will the timing be affected by faster or slower booting machines?
Has anyone got any error trapping script so the script wont get get stuck in a loop etc?
Thanks all.
|
|
Top
|
|
|
|
#28751 - 2002-09-10 06:15 AM
Re: Win9x and Printers
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
pommie,
Since ADDPRINTERCONNECTION, DELPRINTERCONNECTION, are geared for Windows-NT based machines.. You are most likely will have to use SENDKEYS. It would be recommended with SENDKEYS that you test the script thoroughly before use in Production.
HTH,
Kent
|
|
Top
|
|
|
|
#28752 - 2002-09-10 07:34 AM
Re: Win9x and Printers
|
pommie
Fresh Scripter
Registered: 2002-02-01
Posts: 27
|
So no other way to delete printers then?
I'm still concerned about the user get stuck when using sendkeys, especially as we have many hardware models and configurations across many sites.
Is it possible to overwrite existing printer connections. At the moment my sendkeys script, add's the printer as a (copy) of the existing one?
Ta
|
|
Top
|
|
|
|
#28753 - 2002-09-10 07:56 AM
Re: Win9x and Printers
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
pommie,
If we go back and look at the post I referred you to - Add Printer on 9x clients!
Looking at the registry key:
quote:
$localkey = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\Print\Printers"
Notice that he does an ENUMKEY..
And then an ENUMVALUE..
Let's stop here a moment. What are we trying to do? Check to see if a printer exists, if it does not add it.. Otherwise leave the routine.
What is he doing? He is looking for existence of the old printer and the new printer and if the new printer does not exist, add it in..
Look at some of the looping structures used. Pare down what is not needed like $found2 and focus on $found1. In other words, if $found1 exists, RETURN from the sub-routine or EXIT the script.
HTH,
Kent
|
|
Top
|
|
|
|
#28754 - 2002-09-10 08:12 AM
Re: Win9x and Printers
|
pommie
Fresh Scripter
Registered: 2002-02-01
Posts: 27
|
Hi Kent, Yes I have used the script you refered me, thank you for that.
The original script has already defined printer variables and as you mentioned was adding a new printer only if it does not exist.
My needs are different, I need to read the value of the printer connections, delete the printer connection, then re-map the printer connection. (this forces a download from the print server of the new font configuration)
|
|
Top
|
|
|
|
#28756 - 2002-09-10 02:09 PM
Re: Win9x and Printers
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Pommie,
Then I would use the $found1, $found2 format.
In other words, read the information in, delete the printer, re-use the variables and then add it back in.
You could use the Printsetup.ini format that is part of the FAQ we have talked about - Default Printer. In other words, parse out what the printer was into a file.. Delete the printer using either DELVALUE or DELTREE (Deletes parts of the Registry Tree) and then add it back in.
Lonkero - Not sure what you mean by Eventlog. Eventlog is part of NT-Based machines, right? Win9x does not have an Eventlog.
HTH,
Kent
|
|
Top
|
|
|
|
#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 1013 anonymous users online.
|
|
|