0

我有一个桌面应用程序,其中有一个列表视图,里面装满了本地计算机上安装的打印机。这是一个简单的打印机管理,所以我希望能够右键单击一个项目,然后删除该特定打印机。我怎样才能做到这一点?

这是我列出打印机的方式

Public Sub listInstalledPrinters()
        Dim i As Integer
        Dim pkInstalledPrinters As String

        For i = 0 To printersettings.InstalledPrinters.Count - 1
            pkInstalledPrinters = PrinterSettings.InstalledPrinters.Item(i)
            listViewLocal.Items.Add(pkInstalledPrinters, nIndex)
        Next

    End Sub

但是我怎样才能删除其中之一呢?有内置的方法吗?

4

1 回答 1

3

如果您通过 查询打印机,您可以使用类的方法System.Management.ManagementScope轻松删除它们。DeleteManagementObject

Dim scope = New ManagementScope(ManagementPath.DefaultPath)
scope.Connect()
Dim printers = New ManagementObjectSearcher(scope, new SelectQuery("select * from Win32_Printer")).[Get]()
For Each printer As ManagementObject In printers
    Dim nameOfPrinter = printer("Name").ToString()

     If nameOfPrinter = "ThePrinterYouWantToDelete" Then
         printer.Delete()
     End If
Next
于 2012-10-05T11:52:02.510 回答