Page 1 of 1 1
Topic Options
#174877 - 2007-03-22 06:34 PM DelPrinterConnection sloooooooooow
laurin1 Offline
Fresh Scripter

Registered: 2005-10-21
Posts: 6
Why is this function so slow and lock up the system at times when the printers it's trying delete do not exist? Is there any way to check for printer connections before I delete them? I've got a long list of printers that I'm cleaning up off the machines and once the printers have been deleted, it takes forever each time it runs.
_________________________
Hello? - Pedro

Top
#174878 - 2007-03-22 06:49 PM Re: DelPrinterConnection sloooooooooow [Re: laurin1]
Nash Offline
Fresh Scripter

Registered: 2007-03-21
Posts: 7
Watch to see if it serves this to him
http://www.kixtart.org/forums/ubbthreads...=true#Post83885

Top
#174884 - 2007-03-22 07:16 PM Re: DelPrinterConnection sloooooooooow [Re: laurin1]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Maybe first check if the printer is installed on the computer by looking in the registry. I think the PriMapState() UDF can help you.
Top
#174886 - 2007-03-22 07:20 PM Re: DelPrinterConnection sloooooooooow [Re: Nash]
laurin1 Offline
Fresh Scripter

Registered: 2005-10-21
Posts: 6
Very cool. Looks like I'll have to convert it to work for printers by name, rather than the default, but should be possible. Right?
_________________________
Hello? - Pedro

Top
#174887 - 2007-03-22 07:24 PM Re: DelPrinterConnection sloooooooooow [Re: laurin1]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
I think you do not have to convert anything about the UDF. I think you just should use it.
To keep everything simple, I also think it is advisable when creating printers, to keep the "Name" and the "ShareName" the same.

Top
#174888 - 2007-03-22 07:26 PM Re: DelPrinterConnection sloooooooooow [Re: laurin1]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
You could first enumerate the installed network printers and remove them one by one.
Tested it and it is d#mn fast. Maybe something should be changed if you have local printers installed but I can't test this right now because I have no local printers connected to my system.

 Code:
Break on

$Index = 0

While @ERROR = 0
	$printer = EnumKey("HKEY_CURRENT_USER\Printers\Connections\", $Index)
	If $printer <> ""
		$printer = Join(Split ($printer, ","),"\")
		$rc = DelPrinterConnection($printer)
	EndIf
	
	$Index = $Index + 1
Loop
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#174889 - 2007-03-22 07:28 PM Re: DelPrinterConnection sloooooooooow [Re: Witto]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
 Quote:

....
To keep everything simple, I also think it is advisable when creating printers, to keep the "Name" and the "ShareName" the same.


Oh so true. You can save yourself a lot of crap this way.
First thing I tell everyone wanting to know anything about network printers.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#174891 - 2007-03-22 07:39 PM Re: DelPrinterConnection sloooooooooow [Re: Mart]
Nash Offline
Fresh Scripter

Registered: 2007-03-21
Posts: 7
This script to my shows to the names of the printers, I to me the problem that I have is that not like putting that Array in a variable to transfer it to menu of selection to see if it serves to you

 Code:
;Function:  
;    PrinterList()  
;  
;Author:  
;    Allen Powell (Al_Po)  
;  
;Version:  
;    1.3.1  (2006/05/10 fixed error detecting Print Servers sharing IP Printers) 
; 
;Revisions 
;    1.3.0  (2005/10/21 added options to distinguish local or remote printers) 
;    1.2.0  (2005/07/19 optimized code) 
;    1.1.0  (2004/08/09 undimmed variable fix) 
;    1.0.0  (2003/06/26 Original) 
;  
;Action:  
;    Creates an array/list of Printers, and optionally their ports installed, on a local or remote computer.&n bsp;  
;  
;Syntax:  
;    Printerlist(optional $remotepc,optional $displaymode)  
;  
;Parameters:  
;       $RemotePC: (Optional)  
;        Remote Computer. If omitted defaults to localpc.  
;       $DisplayMode (Optional)  
;        0 - show all printers, don't display port info (Default)  
;        1 - show all printers, display port info  
;        2 - show local printers, don't display port info  
;        3 - show local printers, display port info  
;        4 - show remote printers, don't display port info  
;        5 - show remote printers, display port info  
;Returns:  
;     Array of Printers  
;  
;Dependencies:  
;     WMI  
;  
;Example:  
;  
COLOR g+/n
break on  
$RC=Setoption("WrapAtEOL","on") 
 
$array=printerlist()  
for each $printer in $array  
?  $printer  
next  

Function PrinterList(optional $remotepc, optional $displaymode)
  dim $service,$printer,$printers,$printerdesc[0],$counter,$portname,$printername
  if $remotepc=""
     $remotepc="."
  endif
  $Service = GetObject("winmgmts:\\" + $remotepc + "\root\cimv2")
  if @error
    exit @error
  endif
  $Printers=$service.execquery ('select * from Win32_Printer')
  for each $printer in $printers
    redim preserve $printerdesc[$counter]
    if $displaymode & 1
      $portname = "," + $printer.portname
    endif
    select
      case $displaymode & 4 ;remote printers 
        if left($printer.portname,2)="\\" or left($printer.name,2)=="\\"
          $printername=$printer.name
        endif
      case $displaymode & 2 ;local printers 
        if left($printer.portname,2)<>"\\" and left($printer.name,2)<>"\\"
          $printername=$printer.name
        endif
      case 1 ; all printers 
        $printername=$printer.name
    endselect
    if $printername<>""
      $printerdesc[$counter]=$printername + $portname
      $counter=$counter + 1
      $printername=""
    endif   
  next
  $PrinterList=$printerdesc
endfunction
at (8,20) get $x

Top
#174908 - 2007-03-23 10:03 AM Re: DelPrinterConnection sloooooooooow [Re: Nash]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Sorry but I don’t understand what you mean in your last post..

The script I posted works great. Did you try it?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

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
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.064 seconds in which 0.028 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