0
沒有結果使用下面的代碼,我可以找到並刪除打印隊列「Win32_Printer去哪兒網= TRUE」返回Visual Studio安裝項目
Dim scope = New ManagementScope(ManagementPath.DefaultPath)
scope.Connect()
Dim printers = New ManagementObjectSearcher(scope, New SelectQuery("Select * from Win32_Printer Where Network = TRUE")).[Get]()
MsgBox("Print count: " & printers.Count)
For Each printer As ManagementObject In printers
Dim nameOfPrinter = printer("Name").ToString()
If nameOfPrinter.Contains("BROTHER") OrElse nameOfPrinter.Contains("HP") Then
printer.Delete()
End If
Next
然而,當我移動代碼installer.vb(這是添加到安裝程序項目作爲主輸出(有源)),則返回0 printers.count
更新:如果刪除其中的原因,我可以得到本地打印隊列
<Security.Permissions.SecurityPermission(Security.Permissions.SecurityAction.Demand)> _
Public Overrides Sub Commit(ByVal savedState As _
System.Collections.IDictionary)
Dim scope = New ManagementScope(ManagementPath.DefaultPath)
scope.Connect()
Dim printers = New ManagementObjectSearcher(scope, New SelectQuery("Select * from Win32_Printer Where Network = TRUE")).[Get]()
MsgBox("Print count: " & printers.Count)
For Each printer As ManagementObject In printers
Dim nameOfPrinter = printer("Name").ToString()
If nameOfPrinter.Contains("BROTHER") OrElse nameOfPrinter.Contains("HP") Then
printer.Delete()
End If
Next
有什麼我錯過了補充?請指教,謝謝。