;RemoveNetworkedPrinters.kix
Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')
$SO=SetOption('WrapAtEOL','On')
Dim $PrinterData, $PrinterMap, $Pi, $RC
$PrinterData = QS(EnumPrinterConnections2())
If Ubound($PrinterData) <> -1
For $Pi = 0 To Ubound($PrinterData)
$PrinterMap = Split($PrinterData[$Pi],",",-1)
If InStr($PrinterMap[0],"\\")
? 'Networked Printer name is:' + $PrinterMap[0]
; Remove the semi-colons to actually remove the printers
; $RC = DelPrinterConnection($PrinterMap[0])
; ? 'Error was: ' + @ERROR + ' - ' + @SERROR
EndIf
Next
Else
? 'No printer mappings found.'
EndIf
Function EnumPrinterConnections2()
Dim $WshNetwork, $oPrinters, $i, $PrintArray[0]
$EnumPrinterConnections2=""
$WshNetwork = CreateObject("WScript.Network")
If Not @ERROR
$oPrinters = $WshNetwork.EnumPrinterConnections
For $i = 0 To $oPrinters.Count - 1 Step 2
$PrintArray[Ubound($PrintArray)]=$oPrinters.Item($i+1)+','+$oPrinters.Item($i)
ReDim Preserve $PrintArray[Ubound($PrintArray)+1]
Next
If Ubound($PrintArray) > 0
ReDIM Preserve $PrintArray[UBound($PrintArray)-1]
Else
$PrintArray = 0
EndIf
Else
$EnumPrinterConnections2=@ERROR
Exit $EnumPrinterConnections2
EndIf
$EnumPrinterConnections2=$PrintArray
EndFunction
function qs($a)
DIM $b[32],$c[32],$d,$e,$f,$g,$h,$i,$j,$k,$l
$b[0]=0
$c[0]=UBOUND($a)
$d=0
While $d >=0
$e=$b[$d]
$f=$c[$d]
While $e < $f
$h=$e+($f-$e)/2
$k=$a[$e]
$A[$e]=$A[$h]
$A[$h]=$k
$i=$e+1
$j=$f
$l=0
Do
While ($i<$j) AND $A[$e] > $A[$i]
$i=$i+1
Loop
While ($j>=$i) AND $A[$j] > $A[$e]
$j=$j-1
Loop
IF $i>=$j
$l=1
ELSE
$k=$A[$i]
$A[$i]=$A[$j]
$A[$j]=$k
$j=$j-1
$i=$i+1
ENDIF
Until $l=1
$k=$a[$e]
$a[$e]=$a[$j]
$a[$j]=$k
$g=$j
If $g-$e <= $f - $g
If $g+1 < $f
$b[$d]=$g+1
$c[$d]=$f
$d=$d+1
Endif
$f=$g-1
Else
If $g-1 > $e
$b[$d]=$e
$c[$d]=$g-1
$d=$d+1
Endif
$e=$g+1
Endif
Loop
$d=$d-1
Loop
$qs=$a
Endfunction