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 VB...here is the vbs/wsh

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


See More: remove printer connection

Report •


#1
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:

http://www.google.co.uk/search?hl=e...

Stuart


Report •

#2
September 10, 2009 at 10:53:37
Answered:

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
Next
ListLocalPrinters()
End Sub


Private Sub ListLocalPrinters()
Try
Dim searcher As New ManagementObjectSearcher("root\CIMV2", _
"SELECT * FROM Win32_Printer  Where Local = FALSE")
lstPrtrToDelete.Items.Clear()
For Each queryObj As ManagementObject In searcher.Get()
lstPrtrToDelete.Items.Add(queryObj("DeviceID"))
Next
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