プロが教える店舗&オフィスのセキュリティ対策術

スクリプト(VBS)を使用してインストールされている複数のプリンタの中から指定のいくつかプリンタの状態を確認したいのです。例えば:プリンタが A~Zまであるとします。
確認したい指定のプリンタはA~GそしてDです。
環境は WinXP Pro /Service Pack3 です。
どなたか教えて頂けないでしょうか。

A 回答 (2件)

[WMI for VBS]


http://www.wmifun.net/sample/win32_printer_d.html
こちらを参考にしてみてください。

また、プリンタの『何の』状態を確認したいのかによってプロパティを探る必要が出てきます。

Option Explicit
Const OUTTXT = "C:\TEMP\TMP20110305.txt" '出力ファイル名.上書きなので既存ファイルに注意
Dim fso, txt, obj, p
Set fso = CreateObject("Scripting.FileSystemObject")
Set txt = fso.CreateTextFile(OUTTXT)
With CreateObject("WbemScripting.SWbemLocator").ConnectServer
For Each obj In .ExecQuery("Select * From Win32_Printer")
'Select Case obj.Name
'Case "PRT_A", "PRT_B", "PRT_C", "..."
txt.WriteLine "【PrinterName】" & vbTab & obj.Name
txt.WriteBlankLines 1
'SWbemPropertyを列挙
For Each p In obj.properties_
txt.Write p.Name & vbTab
If Not IsArray(p.Value) And Not IsNull(p.Value) Then
txt.Write p.Value
End If
txt.WriteBlankLines 1
Next
txt.WriteBlankLines 1
'End Select
Next
End With
txt.Close
Set txt = Nothing
Set fso = Nothing
MsgBox "finish."

こんな感じのスクリプトで確認できますから、必要なプロパティを探ってみてください。
プリンタの指定は、コメントアウトしてる箇所のように、必要な.Nameで条件分岐すると良いと思います。

この回答への補足

回答ありがとうございます。参考になりました。もう一件質問をさせて頂きますのでよろしくお願いします。下記のWebサイドで15分以上のPrintQが存在すればそのプリンタのステータスを表示。ここでプリンタを[Printer-A/Printer-C/Printer-S]指定していくつかのプリンタのみPrintQのステータス表示することって出来るでしょうか。http://www.activexperts.com/activmonitor/windows …

よろしくお願いします。

補足日時:2011/03/15 06:11
    • good
    • 0

>プリンタの指定は、コメントアウトしてる箇所のように、必要な.Nameで条件分岐すると良いと思います。


と既に書いてます?

>TimeinQueue = DateDiff("n", actualTime, Now)
TimeinQueue = DateDiff("n", dtmActualTime, Now)
ついでの修正をして、


For Each objPrinter in colInstalledPrinters
DateTime.Value = objPrinter.TimeSubmitted
dtmActualTime = DateTime.GetVarDate(USE_LOCAL_TIME)
TimeinQueue = DateDiff("n", dtmActualTime, Now)
If TimeinQueue > 15 Then
strPrinterName = Split(objPrinter.Name, ",", -1, 1)(0)
Select Case strPrinterName
Case "Printer-A", "Printer-C", "Printer- S"
Wscript.Echo strPrinterName & ", " _
& objPrinter.JobID & ", " _
& dtmactualTime & ", " _
& objPrinter.TotalPages
End Select
End If
Next

..こんな感じです。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!