Page 1 of 1 1
Topic Options
#191950 - 2009-01-28 09:41 PM Please help me convert VBS to Kixtart
cryolyte Offline
Just in Town

Registered: 2009-01-28
Posts: 4
Loc: Kalamazoo, Mi
I tried using the UDF. I really did.

My VBScript:
-----------------------


 Code:
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
#191951 - 2009-01-28 10:19 PM Re: Please help me convert VBS to Kixtart [Re: cryolyte]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
Someone correct me if I am wrong, but I think this can be neatly cleaned up into one line

 Code:
$RC=DelPrinterConnection("")

Now tell me Kixtart is not friendlier than VBScript. ;\)
_________________________
(... better days ahead)

Top
#191952 - 2009-01-28 10:20 PM Re: Please help me convert VBS to Kixtart [Re: cryolyte]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
It's already been done for you. Take a look at one of the many UDF scripts already pre-written.

http://www.kixtart.org/udf/


EnumPrinterConnections2() - Enumerates all connected printers

Top
#191954 - 2009-01-28 10:30 PM Re: Please help me convert VBS to Kixtart [Re: NTDOC]
cryolyte Offline
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
#191955 - 2009-01-28 10:31 PM Re: Please help me convert VBS to Kixtart [Re: cryolyte]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
See my post above.
_________________________
(... better days ahead)

Top
#191970 - 2009-01-29 03:54 PM Re: Please help me convert VBS to Kixtart [Re: Allen]
cryolyte Offline
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
#191972 - 2009-01-29 05:51 PM Re: Please help me convert VBS to Kixtart [Re: cryolyte]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
Okay... I thought that "" thing worked... what version of kix are you using?

Also, as Doc suggested, in the UDF Forum there is this. Give it whirl.
DelPrinterConnections: http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=83797#Post83797
_________________________
(... better days ahead)

Top
#191975 - 2009-01-29 07:46 PM Re: Please help me convert VBS to Kixtart [Re: Allen]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
 Quote:
DelPrinterConnection( )

Action: Deletes a connection to a printer that was established by using AddPrinterConnection.

Syntax: DELPRINTERCONNECTION ("printer name")

Parameters: Printer name
A string that specifies the name of the printer connection to delete.

Remarks: This function is only available on Windows NT/2000.
The DELPRINTERCONNECTION function does not delete any printer driver files that were copied from the server on which the printer resides when the printer connection was established.


Returns: 0 Printer connection deleted
Error code Function failed


See Also: AddPrinterConnection( )

Example: If DelPrinterConnection ("hplaser4") = 0
? "Deleted printer connection...."
Endif



Does not appear to support Wild Card * so would have to loop through each one basically like Lonkero did in that UDF post you pointed to.

Top
#191979 - 2009-01-29 10:30 PM Re: Please help me convert VBS to Kixtart [Re: NTDOC]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Here... this code will remove Networked connected printers only and leave the local ones alone.


 Code:
;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
#191980 - 2009-01-29 11:50 PM Re: Please help me convert VBS to Kixtart [Re: NTDOC]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
Somewhere there is a post saying that the "" works... even Lonk mentions it in the header of his UDF. IDK... I never tried it.
_________________________
(... better days ahead)

Top
#191986 - 2009-01-30 09:30 AM Re: Please help me convert VBS to Kixtart [Re: Allen]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
doc?
why do script when there is written udf for that already?

allen, yes, this was discussed back then.
the not working delprinterconnection() was posted even as bug, iirc.
then, when there was no fix for that missing undocumented feature, I wrote the udf.
_________________________
!

download KiXnet

Top
#191999 - 2009-01-30 10:10 PM Re: Please help me convert VBS to Kixtart [Re: Lonkero]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
It gave me a little practice. I don't write too many scripts these days.
Top
#192071 - 2009-02-05 05:04 PM Re: Please help me convert VBS to Kixtart [Re: NTDOC]
cryolyte Offline
Just in Town

Registered: 2009-01-28
Posts: 4
Loc: Kalamazoo, Mi
You guys are great; thanks a ton!
Top
#192081 - 2009-02-05 10:16 PM Re: Please help me convert VBS to Kixtart [Re: NTDOC]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
@doc, ok, I forgive you ;\)
_________________________
!

download KiXnet

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
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.076 seconds in which 0.031 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