首页 > 代码库 > Microsoft Windows Scripting Self-Paced Learning Guide

Microsoft Windows Scripting Self-Paced Learning Guide

http://www.mums.ac.ir/shares/hit/eduhit/book/windowsscripting.pdf
http://support.microsoft.com/kb/926352/en-us
https://www.microsoft.com/learning/en-us/book.aspx?id=6789
FilterPrinterStatus.vbs

Option Explicit‘On Error Resume NextDim strComputerDim wmiNSDim wmiQueryDim objWMIServiceDim colItemsDim objItemDim strStatusstrComputer = "."wmiNS = "\root\cimv2"wmiQuery = "Select * from Win32_Printer" _& " Where PrinterStatus = 1" _& " or PrinterStatus = 2" _& " or PrinterStatus = 7"Set objWMIService = GetObject("winmgmts:\\" _& strComputer & wmiNS)Set colItems = objWMIService.ExecQuery(wmiQuery)If colItems.Count = 0 ThenWScript.Echo "all printers are fine"ElseFor Each objItem In colItemsWScript.Echo "Name: " & objItem.NameWScript.Echo "Location: " & objItem.LocationsubEvalStatusWScript.Echo "Printer Status: " & strStatusWScript.Echo "Server Name: " & objItem.ServerNameWScript.Echo "Share Name: " & objItem.ShareNameWScript.EchoNextEnd IfSub subEvalStatusSelect Case objItem.PrinterStatusCase 1strStatus = "Other"Case 2strStatus = "Unknown"Case 3strStatus = "Idle"Case 4strStatus = "Printing"Case 5strStatus = "Warmup"Case 6strStatus = "Stopped Printing"Case 7strStatus = "Offline"End SelectEnd Sub