remove printer connection

September 1, 2009 at 13:58:38
Specs: Windows XP
I have been tasked with converting our vbscripts to vb executables. One script uses WSH to delete network printers and I can't figure out how to accomplish the same task using is the vbs/wsh

Set objNetwork = CreateObject("Wscript.Network")
objNetwork.RemovePrinterConnection objPrinter.Name

See More: remove printer connection

Report •

September 1, 2009 at 14:18:36
If you are converting to VB I would get rid of WSH altogether. It is far to slow and cumbersome to use withing VB. Most things done with WSH can be achieved via the API which is faster and more eficient.

Try some of these:


Report •

September 10, 2009 at 10:53:37

Private Sub btnRemovePrinters_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeletePrinter.Click
Dim PrtrToDel = Me.lstPrtrToDelete.Items
Dim Prtr As ListViewItem
For Each Prtr In PrtrToDel
If Prtr.Selected = True Then
Call DeletePrinterConnection(Prtr.Text)
End If
End Sub

Private Sub ListLocalPrinters()
Dim searcher As New ManagementObjectSearcher("root\CIMV2", _
"SELECT * FROM Win32_Printer  Where Local = FALSE")
For Each queryObj As ManagementObject In searcher.Get()
lstPrtrToDelete.View = View.List
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
End Try
End Sub

Report •

Related Solutions

Ask Question