#191950 - 2009-01-28 09:41 PM
Please help me convert VBS to Kixtart
|
cryolyte
Just in Town
Registered: 2009-01-28
Posts: 4
Loc: Kalamazoo, Mi
|
I tried using the UDF. I really did.
My VBScript: -----------------------
Set WshShell = WScript.CreateObject("Wscript.Shell")
On Error Resume Next
Set objNet = CreateObject("WScript.Network")
Set colOfNetPrinters = objNet.EnumPrinterConnections
On Error Resume Next
For i = 0 to colOfNetPrinters.Count -1 Step 2
' operate only on UNC based printer connections
If Left(colOfNetPrinters.Item(i+1), 2) = "\\" Then
objNet.RemovePrinterConnection colOfNetPrinters.Item(i+1), True, True
If err.number <> 0 Then
WSCript.Echo "An error occuried trying to remove printer connection " _
& colOfNetPrinters.Item(i+1) & " The error number is " & err.number _
& " error description " & err.description
err.clear
End If
End If
Next
On Error Resume Next
----------------------
Thanks for any help.
|
|
Top
|
|
|
|
#191954 - 2009-01-28 10:30 PM
Re: Please help me convert VBS to Kixtart
[Re: NTDOC]
|
cryolyte
Just in Town
Registered: 2009-01-28
Posts: 4
Loc: Kalamazoo, Mi
|
The purpose of the VBScript is to delete all network printers. Physical printers must be left alone.
I really do appreciate the help.
Edited by cryolyte (2009-01-28 10:30 PM)
|
|
Top
|
|
|
|
#191970 - 2009-01-29 03:54 PM
Re: Please help me convert VBS to Kixtart
[Re: Allen]
|
cryolyte
Just in Town
Registered: 2009-01-28
Posts: 4
Loc: Kalamazoo, Mi
|
I pasted your line of code into notepad and saved the file to c:\kix\tryme.kix
Then, I went to the CLI, navigated to C:\kix, and typed: kix32 tryme.kix
All of my printers are still there.
|
|
Top
|
|
|
|
#191979 - 2009-01-29 10:30 PM
Re: Please help me convert VBS to Kixtart
[Re: NTDOC]
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11634
Loc: Space
|
Here... this code will remove Networked connected printers only and leave the local ones alone.
;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
|
|
Top
|
|
|
|
#192071 - 2009-02-05 05:04 PM
Re: Please help me convert VBS to Kixtart
[Re: NTDOC]
|
cryolyte
Just in Town
Registered: 2009-01-28
Posts: 4
Loc: Kalamazoo, Mi
|
You guys are great; thanks a ton!
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|