以Script的方式快速移除使用者電腦的各種印表機
群組原則只能控制用戶能不能增減, 卻沒有一次過剷除各種印表機的選項
有時候舊有或這壞掉的印表機需要在用戶端大規模移除, 除了逐個用戶電腦探訪, 其實用logon script就能輕鬆辦到
我列舉出幾個比較常用的配搭, 每段Script只要儲存為.vbs再雙擊就能運行,
如果你要設定成批次檔執行一個.vbs你可以用cscript.exe來運行
以下是移除所有印表機
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer") For Each objPrinter in colInstalledPrinters objPrinter.Delete_ Next
以下是移除所有”非網絡”(Local Printer)印表機
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Network = FALSE")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next
以下能夠移除名稱為'Kyocera FS-3920DN ACC'的印表機 (就是新增印表機時建立的名字)
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Caption = 'Kyocera FS-3920DN ACC'")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next
其他能夠用的WMI Class Name請查找:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394363(v=vs.85).aspx