2010年3月3日

script新增/移除印表機範例

Code Snippet
Const NETWORK = 22
Set objNetwork = CreateObject("WScript.Network")
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")
For Each objPrinter in colPrinters
If objPrinter.Attributes And NETWORK Then
strPrinter = objPrinter.Name
objNetwork.RemovePrinterConnection strPrinter
End If
Next


以上的Script是移除所有的網路印表機.
Code Snippet
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where Local = TRUE")
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\PrintServer1\Xerox300"
If colPrinters.Count = 0 Then
objNetwork.SetDefaultPrinter "\\PrintServer1\Xerox300"
End If
以上是新增PrinterServer1上的Xerox300印表機並設為預設印表機的範例

0 意見:

張貼留言

##EasyReadMore##