What language is this? How can I use this script?

Hi! I am not a programmer, but I am pretending. Please help me.

Microsoft has this little script on their site. I want to run it. Only a couple minor problems:

  1. I have no idea what language this is in.
  2. I have no idea how to execute this script.

Any help?

Print Monitor Script

Part 2.
My goal is to basically take this script, have it monitor the print queu for a specific printer, and if the queu ever has >0 jobs, to play a .wav file.

Extra bonus points if you help me with part 2!

HELP PLEASE!

It looks like Windows scripting, so try putting it in a file that has a .wsh extension. Then you should just be able to double-click it.

Gar, didn’t I just get done doing this for eight hours today. :slight_smile:



Option Explicit

Dim strComputer, strTargetPrinter, strWaveFile
Dim objWMIService, objPrintQueue, colPrintQueues, objShell

strComputer = "."
strTargetPrinter = "hp deskjet 3820 series"
strWaveFile = "c:\windows\media\ding.wav"

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintQueues =  objWMIService.ExecQuery _
    ("Select * from Win32_PerfFormattedData_Spooler_PrintQueue Where Name = '" & strTargetPrinter & "'")

For Each objPrintQueue in colPrintQueues
    If objPrintQueue.Jobs <> "0" Then
        Set objShell = CreateObject("Wscript.Shell")
        objShell.Run "sndrec32 /play /close """ & strWaveFile & """",0,True
        Set objShell = Nothing
    End if
Next


Change the variables at the beginning to the server, printer, and wave file you want. Save it as WHATEVER.vbs, and double click to run.

However, this is a one-shot deal. If you want, you can schedule it to run every X minutes. If needed, I could modify to have it sleep for a while, then check again.

Let me know if you need any other help.

If I had known you were going to do that for me, I wouldn’t have spent 5 hours figuring out how to write a vbscript like that myself.

Thanks a ton! I figured out how to do the sleep thing too. :slight_smile:

Matt