Query if Monitor is off?

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
May 29, 2011
17
0
Seattle
#1
Reboot /M1 powers the monitor off. Is there a way to query in a batch file if the monitor is actually off? (My batch file occasionally ftp's the screen @snapshot[] and it would be nice to know if the screen is on or off).
 
#2
From: TonyT
| Reboot /M1 powers the monitor off. Is there a way to query in a batch
| file if the monitor is actually off? (My batch file occasionally
| ftp's the screen @snapshot[] and it would be nice to know if the
| screen is on or off).


When the monitor is turned off by REBOOT /M1 (or its equivalent), would @SNAPSHOT return the "virtual screen", i.e., that which would be displayed if the monitor were on?

A question similar to the one in the OP that's related to REBOOT /W: would internal variables _READY and _HDRIVES indicate whether or not the disk drive power is currently on?
--
Steve
 
May 29, 2011
17
0
Seattle
#3
From: TonyT
| Reboot /M1 powers the monitor off. Is there a way to query in a batch
| file if the monitor is actually off? (My batch file occasionally
| ftp's the screen @snapshot[] and it would be nice to know if the
| screen is on or off).


When the monitor is turned off by REBOOT /M1 (or its equivalent), would @SNAPSHOT return the "virtual screen", i.e., that which would be displayed if the monitor were on?

A question similar to the one in the OP that's related to REBOOT /W: would internal variables _READY and _HDRIVES indicate whether or not the disk drive power is currently on?
--
Steve
I am not actually using @Snapshot, but IrfanView /capture and the captures always show the pictures as if the screen is on. That PC is thousands of miles away from me, so I'd like to know if the monitor state is really off.
 
#4
From: TonyT
| I am not actually using @Snapshot, but IrfanView /capture and the captures always show
| the pictures as if the screen is on. That PC is thousands of miles away from me, so I'd like
| to know if the monitor state is really off.

Is the real issue that you want to know the state of the monitor of a remote system under your control? And your approach is to capture the screen display of TCC running on that system?

BTW, please do NOT quote signatures and signature separators (the line containg just two hyphens followed by a space, see below in this post). Those of us who try to respond to your post by email, all of your post remains unquoted. I had to manually quote it above. Quote only as little as is necessary to understand your new post.
--
Steve
 
May 29, 2011
17
0
Seattle
#5
| Is the real issue that you want to know the state of the monitor of a remote system under your control? And your approach is to capture the screen display of TCC running on that system?

The PC is under my control, unattended far away. I basically want the monitor off all the time to save power and not burn a hole in the laptop screen etc.. So I issue a monitor off command. Frequently the system posts the screen capture (with stuff it is crunching out) to a homepage and that is working fine. But is the monitor really off? Or has somebody touched a key and it is on again? An internal variable like @MonitorStatus[] would be ideal, but I looked far and wide for a way to tell if it's on with no luck. "Win32_DesktopMonitor Class Status" I suppose could in a c program, but I don't know how to do that.


| BTW, please do NOT quote signatures and signature separators (the line containg just two hyphens followed by a space, see below in this post). Those of us who try to respond to your post by email, all of your post remains unquoted. I had to manually quote it above. Quote only as little as is necessary to understand your new post.

I'm quite new to forums, so I deleted the hyphens and next line but don't know if it is better now.
 
May 30, 2008
206
1
#7
The PC is under my control, unattended far away. I basically want the monitor off all the time to save power and not burn a hole in the laptop screen etc.. So I issue a monitor off command.
Why not use the Windows power management options to turn the screen off after a while?
 
May 29, 2011
17
0
Seattle
#8
| Why not use the Windows power management options to turn the screen off after a while?

The Notebook is actually doing data acquisition for building movements and in windstorms somebody might actually want to observe it on site - so it turning off unexpectedly would be annoying.

Now there is just no way for me to tell the monitor status remotely (or the automatic procedures that the notebook is running) if I can not find some utility or internal variable to determine the status.
 
May 29, 2011
17
0
Seattle
#9
| Why not use the Windows power management options to turn the screen off after a while?

Another example: Say I want to turn the screen ON for this monitoring laptop for people on site when wind-speeds it monitors are above 30mph. How could I ever tell if it is actually on when this laptop is thousands of miles away from me. I might "blindly" think my batch files turned it on, but is it? A %_MonitorStatus[] or %MonitorStatus[] like utility or variable is what I need then I can simply DisplayWrite it on the screen before I capture it and post the screen capture to a webpage I frequently look at.
 
#10
On Mon, 30 May 2011 13:03:12 -0400, TonyT <> wrote:

|A %_MonitorStatus[] or %MonitorStatus[] like utility or variable is what I need

I hope I'm wrong but I don't think this is easy to do it. I googled quite a
bit. There may be a way to do it with WMIQUERY/@WMI but I couldn't find it
(anyone?). I found some rather complicated code (which uses the setup API) that
can tell the difference between these:

Code:
# Monitors = 4
[Default Monitor]
   PowerState = 1
[Default Monitor]
   PowerState = 1
[Dell 1908FP(Digital)]
   PowerState = 1
[Plug and Play Monitor]
   PowerState = 1
and
Code:
# Monitors = 4
[Default Monitor]
   PowerState = 4, *** Sleeping State ***
[Default Monitor]
   PowerState = 4, *** Sleeping State ***
[Dell 1908FP(Digital)]
   PowerState = 4, *** Sleeping State ***
[Plug and Play Monitor]
   PowerState = 4, *** Sleeping State ***
on my Dell WKS with two physical monitors before/after I put them into standby.
But if I simply turned on off (physically) it couldn't tell.
 
May 29, 2011
17
0
Seattle
#11
|A %_MonitorStatus[] or %@MonitorStatus[] like utility or variable is what I need

| I hope I'm wrong but I don't think this is easy to do it. I googled quite a
bit. There may be a way to do it with WMIQUERY/@WMI but I couldn't find it
(anyone?). I found some rather complicated code (which uses the setup API) that
can tell the difference between these:

Code:
# Monitors = 4
[Default Monitor]
   PowerState = 1

Thanks for your interesting idea.  I searched the registry for "PowerState" but only found  Settings nothing for state.  Even windows own powercfg does not report the state, just settings.
 
#12
On Mon, 30 May 2011 13:45:59 -0400, vefatica <> wrote:

|on my Dell WKS with two physical monitors before/after I put them into standby.

Interestingly, this simple code can tell whether the monitor is in (any) power
saving mode. But it can't tell if I have physically turned the monitor off. I
could easily include it in one of my plugins but I am uncertain about its value.

Code:
HANDLE hLCD = CreateFile(L"\\\\.\\LCD", GENERIC_READ | GENERIC_WRITE, 0,
0, OPEN_EXISTING, 0, 0);
BOOL bOn;
if ( GetDevicePowerState (hLCD, &bOn) )
	wprintf(L"State: %d\n", bOn);
else
	wprintf(L"Failed: %d\n", GetLastError());
CloseHandle(hLCD);
Code:
g:\projects\test\release> test.exe
State: 1

g:\projects\test\release> monitor off & delay 10 & test.exe
State: 0
Above, the "monitor" command sends (WM_SYSCOMMAND, SC_MONITORPOWER, flag).
Whether I give the power_down flag or the off flag, the monitor powers down.

When I do the above via RemoteDesktop on a computer which was locked and had its
monitors physically turned off 4 days ago, I get the seemingly correct result
... "State: 0".
 
May 29, 2011
17
0
Seattle
#13
|on my Dell WKS with two physical monitors before/after I put them into standby.

| Interestingly, this simple code can tell whether the monitor is in (any) power
saving mode. But it can't tell if I have physically turned the monitor off.

Thanks Vince. I think I can use your code to do exactly what I want. I am a bit embarrassed I could not compile the code yet with TinyC ( http://bellard.org/tcc/ ) but will keep trying. It is such simple code but I am a lousy c programmer (expert in Fortran that tells my age). Could you just send me the compiled program, e.g. anonymously put in the inbox of ftp.mka.com ?

I don't need to know if unplugged, just if it is in the power saving mode.

Thanks a lot.
Tony
 
#14
On Mon, 30 May 2011 15:48:13 -0400, TonyT <> wrote:

|Thanks Vince. I think I can use your code to do exactly what I want. I am a bit embarrassed I could not compile the code yet with TinyC ( http://bellard.org/tcc/ ) but will keep trying. It is such simple code but I am a lousy c programmer (expert in Fortran that tells my age). Could you just send me the compiled program, e.g. anonymously put in the inbox of ftp.mka.com ?
|
|I don't need to know if unplugged, just if it is in the power saving mode.

I could certainly do that but I'll have to tidy it up first, I'll call it
QUERYLCD.EXE, and make it a console app printing **and** returning 1 or 0. Look
for it in a few minutes.
 
#15
On Mon, 30 May 2011 15:48:13 -0400, TonyT <> wrote:

|ftp.mka.com

I uploaded it as QUERYLCD.ZIP. Here's what I built:

Code:
int main()
{
	INT rv = -1;
	HANDLE hLCD 		CreateFile(L"\\\\.\\LCD", GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
	BOOL bOn;
	if ( GetDevicePowerState (hLCD, &bOn) )
		rv = bOn ? 1 : 0;
	else
		wprintf(L"GetDevicePowerState failed: %d\n", GetLastError());
	CloseHandle(hLCD);
	wprintf(L"%d\n", rv);
	return rv;
}
 
May 29, 2011
17
0
Seattle
#18
| I uploaded it as QUERYLCD.ZIP. Here's what I built:

Vance, Thank you so very much. It works excellently and is exactly what I need. A problem solved that confounded me for months! Sorry to not get back right away, I had to go away for the day.

Tony
 
May 29, 2011
17
0
Seattle
#19
| I rather doubt that you will because there are no includes for the header files in Vince's source code.

I had added the #include windows.h and even #include stdio.h but I guess more was needed.


| Perhaps not, and with something like the Open Watcom compiler it ought to be possible to convert Vince's program

Thanks for this great hint, Steve. I am looking forward to playing with that and some C programs I use.

Tony
 
#20
On Tue, 31 May 2011 11:05:37 -0400, TonyT <> wrote:

|| I rather doubt that you will because there are no includes for the header files in Vince's source code.
|
|I had added the #include <windows.h> and even #include <stdio.h> but I guess more was needed.

Those two are the only includes I had in there. You probably also needed a
compiler option for Unicode because I used L"\\\\.\\LCD"; it's /D "_UNICODE" /D
"UNICODE" here. Just getting rid of the "L" qualifier might work as well.
 
May 29, 2011
17
0
Seattle
#21
| Hence I still don't have a solution to know whether the remote laptop's screen is on or off.

vefatica solved it! Using a setup API approach that looks quite ingenious and works on all devices I tried.

Rex Conn: Any possibility to incorporate his method to make a new internal variable _MonitorStatus[] in a future release of TCC that shows if a monitor is on or in sleeping state?

Tony
 
May 29, 2011
17
0
Seattle
#22
| Hence I still don't have a solution to know whether the remote laptop's screen is on or off.

Trying again to make it show as a new post ...

vefatica solved it! Using a setup API approach that looks quite ingenious and works on all devices I tried.

Rex Conn: Any possibility to incorporate his method to make a new internal variable _MonitorStatus[] in a future release of TCC that shows if a monitor is on or in sleeping state?

Tony
 
#24
On Wed, 01 Jun 2011 12:49:13 -0400, TonyT <> wrote:

|| Hence I still don't have a solution to know whether the remote laptop's screen is on or off.
|
|Trying again to make it show as a new post ...
|
|vefatica solved it! Using a setup API approach that looks quite ingenious and works on all devices I tried.
|
|Rex Conn: Any possibility to incorporate his method to make a new internal variable _MonitorStatus[] in a future release of TCC that shows if a monitor is on or in sleeping state?

I can only take credit for building some code I googled up. It's not OO but it
uses a lot of STL stuff (for which there's no real need ... Rex, do you use STL
stuff in TCMD?). I'm going to streamline it and see how costly it is to put
into one of my plugins. If it's particularly costly, I'll try rewriting it
without STL.

Basically, it uses the setup API to get it->Description.c_str() and
it->PowerData.PD_MostRecentPowerState for the instances of the "Monitor" classes
(see
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E96E-E325-11CE-BFC1-08002BE10318}).
 
#25
I am looking forward to playing with that and some C programs I use
I have to admit to never having used the Fortran (and indeed the last time I did anything with Fortran - converting Dungeon to run on IBM's mainframe VM OS for a bureau's games system - was back in the early 1980s) but I have used Open Watcom C for virtually the whole of its existence, since my employer previously used the commercial Watcom C for the Windows version of our cross-platform tools.
 
#26
Any possibility to incorporate his method to make a new internal variable _MonitorStatus[] in a future release of TCC that shows if a monitor is on or in sleeping state?
I did manage to get it into a plugin. My first attempt, leaving the Googled code basically "as is", added about 15Kb to my plugin. After getting rid of the STL stuff, a function template, and the getting of device names, I whittled that down to about 1Kb. Rex is welcome to the code but since it's a hack of someone else's code I'll take neither credit nor blame for it.

What I have now works like this, with the second example being when the monitor(s) are in power saving mode.

Code:
v:\> help @video
@VIDEO[N] = 1/0/-1 (on/sleeping/error) for monitor N = 0,1,...

v:\> for /l %i in (0,1,3) echo %@video[%i]
1
1
1
1

v:\> reboot /m1 & delay 15 & for /l %i in (0,1,3) echo %@video[%i]
0
0
0
0
It's a highly specialized function so I don't mind the user having to look in

Code:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E96E-E325-11CE-BFC1-08002BE10318}
to see how many devices exist and their descriptions ... and to experiment as to which of them suit his purposes.

I have two physical monitors attached to a Dell WKS here. And here that registry key enumerates 4 devices; their descriptions are: "Default Monitor", "Default Monitor", "Dell 1908FP(Digital)", and "Plug and Play Monitor" (a bit confusing). In my tests, I always get the same result for all 4.

Tony, would that suit your purposes? Comments, anyone?
 
Aug 9, 2009
133
0
#27
What "I'D" really like @execstr[] to return more than "first" line ...
example exesctr[fc whatever,1]
as an example - fc.exe returns the command parameters while the second
line produces the result I want
"FC: no differences encountered" -a- Plugin would work just as well

feedback:) maybe, will judge by the responses here


> Code:
> ---------
> v:\> help @video
> @VIDEO[N] = 1/0/-1 (on/sleeping/error) for monitor N = 0,1,...
>
> v:\> for /l %i in (0,1,3) echo %@video[%i]
> 1
> 1
> 1
> 1
>
> v:\> reboot /m1 & delay 15 & for /l %i in (0,1,3) echo %@video[%i]
> 0
> 0
> 0
> 0
> ---------
> It's a highly specialized function so I don't mind the user
> having to look in
>
>
> Code:
> ---------
> HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D3
> 6E96E-E325-11CE-BFC1-08002BE10318}
> ---------
> to see how many devices exist and their descriptions ... and
> to experiment as to which of them suit his purposes.
>
> I have two physical monitors attached to a Dell WKS here.
> And here that registry key enumerates 4 devices; their
> descriptions are: "Default Monitor", "Default Monitor", "Dell
> 1908FP(Digital)", and "Plug and Play Monitor" (a bit
> confusing). In my tests, I always get the same result for all 4.
>
> Tony, would that suit your purposes? Comments, anyone?
 

rconn

Administrator
Staff member
May 14, 2008
10,100
85
#29
What "I'D" really like @execstr[] to return more than "first" line ...
example exesctr[fc whatever,1]
as an example - fc.exe returns the command parameters while the second
line produces the result I want
"FC: no differences encountered" -a- Plugin would work just as well
@EXECSTR already supports an optional argument to specify the line you want.
 
May 29, 2011
17
0
Seattle
#30
| v:\> for /l %i in (0,1,3) echo %@video[%i]
| 1

| Tony, would that suit your purposes? Comments, anyone?

Yes, this looks like great solution and I'm looking forward to use it

Tony