Jump to content

Check and set Printer online/offline status


czyt
 Share

Recommended Posts

This is a very simple sample about checking printer status and set its online/offline status.may help those who in need of this issue.

$StrComputer="."
$obj=ObjGet("winmgmts:\\"&$StrComputer&"\root\CIMV2")
$colitems=$obj.ExecQuery("Select * from Win32_Printer")
For $objitem In $colitems
        If $objitem.Caption=="SHARP AR-1808S" Then
                $a=Int($objitem.Attributes / 1024)
                If Mod($a, 2)=0 Then
                        MsgBox(0,0,"Printer is online",8)
                    ElseIf Mod($a, 2)=1 Then
                        MsgBox(0,0,"Printer is offline,press 'OK'button To make the printer online ",8)
                        ;core code
                        $objitem.WorkOffline = False
                        $objitem.Put_
                        ;~~~~~~~~~~~~~~~~~~~~~~
                        MsgBox(0,'','Printer is online now.')
                Else
                        MsgBox(0,0,"unknown status",8)
                EndIf
        EndIf
next

 

Edited by czyt

董小姐,你微笑的时候很美,就像安河桥下,清澈的水...

Link to comment
Share on other sites

  • 6 years later...
On 12/4/2015 at 5:36 AM, czyt said:

This is a very simple sample about checking printer status and set its online/offline status.may help those who in need of this issue.

$StrComputer="."
$obj=ObjGet("winmgmts:\\"&$StrComputer&"\root\CIMV2")
$colitems=$obj.ExecQuery("Select * from Win32_Printer")
For $objitem In $colitems
        If $objitem.Caption=="SHARP AR-1808S" Then
                $a=Int($objitem.Attributes / 1024)
                If Mod($a, 2)=0 Then
                        MsgBox(0,0,"Printer is online",8)
                    ElseIf Mod($a, 2)=1 Then
                        MsgBox(0,0,"Printer is offline,press 'OK'button To make the printer online ",8)
                        ;core code
                        $objitem.WorkOffline = False
                        $objitem.Put_
                        ;~~~~~~~~~~~~~~~~~~~~~~
                        MsgBox(0,'','Printer is online now.')
                Else
                        MsgBox(0,0,"unknown status",8)
                EndIf
        EndIf
next

 

Thanks very much ❤

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...