以下是移除所有印表機
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 objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Network = FALSE")
("Select * from Win32_Printer Where Network = FALSE")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next
objPrinter.Delete_
Next
以下能夠移除名稱為'Kyocera FS-3920DN ACC'的印表機 (就是新增印表機時建立的名字)
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Caption = 'Kyocera FS-3920DN ACC'")
("Select * from Win32_Printer Where Caption = 'Kyocera FS-3920DN ACC'")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next
objPrinter.Delete_
Next
strComputer = "."
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
if InStr(objPrinter.Name, "\\") > 0 then
WshNetwork.RemovePrinterConnection objPrinter.Name
end if
Next
Set WshNetwork1 = CreateObject("WScript.Network")
Select Case WshNetWork1.UserName
Case "user1"
PrinterPath = "\\Server1\Print1"
PrinterDriver = "Print1"
WshNetwork1.AddWindowsPrinterConnection PrinterPath, PrinterDriver
PrinterPath = "\\Server2\Print2"
PrinterDriver = "q23"
WshNetwork1.AddWindowsPrinterConnection PrinterPath, PrinterDriver
PrinterPath = "\\Server3\Print3"
PrinterDriver = "Print3"
WshNetwork1.AddWindowsPrinterConnection PrinterPath, PrinterDriver
WshNetwork.SetDefaultPrinter "Server1\Print1"
Case "user2"
PrinterPath = "\\Server1\Print1"
PrinterDriver = "Print1"
WshNetwork1.AddWindowsPrinterConnection PrinterPath, PrinterDriver
PrinterPath = "\\Server2\Print2"
PrinterDriver = "q23"
WshNetwork1.AddWindowsPrinterConnection PrinterPath, PrinterDriver
PrinterPath = "\\Server3\Print3"
PrinterDriver = "Print3"
WshNetwork1.AddWindowsPrinterConnection PrinterPath, PrinterDriver
WshNetwork1.SetDefaultPrinter "\\Server2\Print2"
End Select
=====================================================
每段Script只要儲存為.vbs再雙擊就能運行!
如果你要設定成批次檔執行一個.vbs你可以用script.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
沒有留言:
張貼留言