VBS script to check printer status

Discussion in 'Web Design & Coding' started by j79zlr, Mar 27, 2008.

  1. j79zlr

    j79zlr Glaanies script monkey Political User

    Messages:
    2,725
    Location:
    Chicago
  2. falconguard

    falconguard Carbon based lifeform Political User Folding Team

    Messages:
    3,406
    Location:
    SoCal
    Could he do an lpstat -p?
     
  3. fitz

    fitz Just Floating Along Staff Member Political User Folding Team

    Messages:
    4,076
    Location:
    Chicagoland
    i'm still not quite sure what he's trying to do.. his batch file "example" makes no sense..

    what is this doing?
    Code:
    %SystemRoot%\pv.exe > result.txt 
    
    and why use a vbscript file to just display a message?
    Code:
    call You Have Left The Printer On.vbs
    What he says and what he is showing seem to be two different things..

    Going by what he said, he could create a vbscript file to run as a shutdown script..

    The template below will check the status of the printer and display a box with just an OK button telling him to shut off the printer.

    If he were to, say, go into his local policies and add the script as a shutdown script, it should run.. not sure if/how the message box will display or not in the middle of a shutdown though.

    objPrinter.PrinterStatus=3 is the "ready" printer state
    strPrinter should be set to the name of the printer
    strComputer really isn't necessary as it is just the local PC.. force of habit for me.
    Code:
    'run at shutdown to check the status of a printer
    
    Option Explicit
    Dim objWMI, objPrinter, colPrinters, strComputer,strPrinter,strWMIQuery
    
    strComputer = "."
    strPrinter = "Some Printer Name"
    strWMIQuery = "SELECT * FROM Win32_Printer WHERE name=""" & strPrinter & """"
    
    set objWMI = GetObject ("winmgmts:\\" & strComputer & "\root\CIMV2")
    
    set colPrinters = objWMI.ExecQuery(strWMIQuery)
    
    for each objPrinter in colPrinters
        if not(objPrinter.PrinterStatus=3) then
            msgbox "Turn off the Printer!",0,"Printer Is Still On!"
        end if
    next
    
    wscript.quit
    
     
    Last edited: Mar 27, 2008
  4. j79zlr

    j79zlr Glaanies script monkey Political User

    Messages:
    2,725
    Location:
    Chicago
    Thanks for looking at it. I really don't do any VBS so I would be wildly guessing.