利用WshNetwork对象的RemovePrinterConnection方法可以将本地电脑上连接的远程打印机移除。
代码如下:
Sub QQ1722187970() Dim WshNetwork As Object Dim oPrinter As Object Set WshNetwork = CreateObject("WScript.Network") With WshNetwork Set oPrinter = .EnumPrinterConnections For i = 0 To oPrinter.Count - 1 Step 2 sPath = oPrinter(i + 1) '判断是不是远程打印机 If sPath Like "*\\*" Then '是的话强制断开连接 .RemovePrinterConnection sPath, True, True End If Next i End With End Sub
发表评论