trigger on event (screensaver)?

nnCron and nnCron LITE discussion

trigger on event (screensaver)?

Postby gianni76 » Thu, 24 Nov 2005, 17:14

I don't know if I ask too much.
With nncron LITE, can I trigger the excecution of a program after (or if) an event occurs?

Specifically I would like to run a perl program periodically but I would like this to be run only if/when the screensaver is on.
This is becuase the process is resource intensive and I do not wish to be distrubed or have the PC blocked while I work. But it does not matter if this happens when I am taking a cofee or am far from my PC.

I wonder if nncron Lite allows to skip the scheduled event in case the screensaver is off (i.e. while I am working) or activate the event only if the screensaver is on.

If it is possible, I would also like some pointers to how to 'detect' that the screensaver is on (for example it could be done looking at a specific program running in the task list).
Last edited by gianni76 on Thu, 24 Nov 2005, 20:17, edited 1 time in total.
gianni76
 
Posts: 7
Joined: Thu, 24 Nov 2005, 06:37

Postby VK » Thu, 24 Nov 2005, 17:37

No, as far as I remember there are no words in nnCron LITE word-list, which allows you to check the existance of specified process.

(This can be done easily wih nnCron, which is a full-blown automation manager, but not with nnCron LITE which is a Windows cron-port with some advanced features).
CU
VK
User avatar
VK
 
Posts: 680
Joined: Wed, 14 Jul 2004, 19:17

Postby gianni76 » Thu, 24 Nov 2005, 17:47

Excuse my ignorance,
but looking at the plugin section (and plugins are available for nncron lite), just the first example seems to do something pretty similar. It checks for the calculator app and if not running it launches it.

What I would need to do is to check for the screensaver app and if running launch a perl program.
I know that my screensaver will show in the process list as:

Process name: logon.scr
Path: C:\WINDOWS\System32\logon.scr


Isn't there a way to adapt that calculator example?
Can anyone help? I don't grasp forth but am trying something...


\ --- start of test.spf ---
WINAPI: FindWindowA LOGON.SCR
: LOGON-STARTED? ( -- ? )
Z" logon" 0 FindWindowA 0<>
;
: RUN-PERL
LOGON-STARTED? 0=
IF
ShowNormal
START-APP: C;/perl/bin/perl.exe script.pl
THEN
;
\ --- end of test.spf ---
gianni76
 
Posts: 7
Joined: Thu, 24 Nov 2005, 06:37

Postby VK » Thu, 24 Nov 2005, 18:01

these are different things. the plugin is checking for a window with specified title. AFAIK there is no easy way to find a _process_ with specified name using nnCron LITE. and your screensaver has no window with title...
CU
VK
User avatar
VK
 
Posts: 680
Joined: Wed, 14 Jul 2004, 19:17

Postby gianni76 » Thu, 24 Nov 2005, 19:00

Ok, not very nice then :-(

Maybe some talented coder could have a further thought.
If I understand correctly what you do in the example above is launch a WINAPI message from the plugin.
And maybe there are way to detect the screensaver directly with functions in WINAPI.

For those who want to explore this, here is what microsoft suggest:
http://support.microsoft.com/?kbid=238882
and
http://support.microsoft.com/kb/150785/EN-US/

In particular for win 2000 and later (i.e. also for XP), they suggest to use the flag SPI_GETSCREENSAVERRUNNING within the SystemParametersInfo function.
I am assuming this is a WINAPI function (is it correct?)
If so, can we call it from Forth? How?

Another possible approach would be to check the existence of a desktop named "screen-saver" (this should work on NT, but not sure if it wors on XP as well).
gianni76
 
Posts: 7
Joined: Thu, 24 Nov 2005, 06:37

Postby gianni76 » Thu, 24 Nov 2005, 19:47

Hi,
this is an example of how the function is used in visual basic:
http://www.vb-helper.com/howto_screensaver_running.html

Again this is a test.
Can anyone try this (I do not know how to degub forth) or suggest if there is a better way in Forth?

\ --- start of test.spf ---
WINAPI: SystemParametersInfoA USER32.DLL
: RUN-SCREEN
SystemParametersInfo SPI_GETSCREENSAVEACTIVE, 0, bActive, False
IF
bActive
START-APP: perl.exe script.pl
THEN
;
\ --- end of test.spf ---

In simple pseudo-code this is what the forth .spf should do:

1. call the winAPI function SystemParametersInfoA from user32.dll
2. launch the API command:
SystemParametersInfo SPI_GETSCREENSAVEACTIVE, 0, bActive, False
3. if bActive (i.e. screensaver is on)
then start perl process
otherwise
do nothing

Can anyone help with writing/debugging this forth function?
gianni76
 
Posts: 7
Joined: Thu, 24 Nov 2005, 06:37

Postby Valery_Kondakoff » Thu, 24 Nov 2005, 23:54

This is what I have found:
Code: Select all
BOOL bActive;
   SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, NULL,(LPVOID) &bActive, NULL);
   //bActive will be true if Screen Saver is running


SPI_GETSCREENSAVERRUNNING = 114
CU
VK
User avatar
Valery_Kondakoff
Site Admin
 
Posts: 769
Joined: Thu, 01 Jul 2004, 20:49
Location: Moscow, Russia

Postby gianni76 » Fri, 25 Nov 2005, 00:23

Valery,
I also saw that function call on the Microsoft web site. but that's C.
Now someone needs to make a simple equivalent to Forth and test/debug it.

I have put down the main ideas in my last post above, with an initial version of the spf file that will do it.

Are you (or anyoneelse) capable of testing it and understand any eventual problems? I could only go trial and error and this is not a very good approach if you never ver used that language...
gianni76
 
Posts: 7
Joined: Thu, 24 Nov 2005, 06:37

Postby VK » Fri, 25 Nov 2005, 15:25

Nicholas recommended a more elegant solution:
Code: Select all
WINAPI: SystemParametersInfoA USER32.DLL
: SYS-PAR >R 0 SP@ 0 SWAP 0 R> SystemParametersInfoA DROP ;
: RUN-YOUR-PROG
0x0072 SYS-PAR 0<>
IF
    ShowNormal
    START-APP: your_app.exe
THEN
;
CU
VK
User avatar
VK
 
Posts: 680
Joined: Wed, 14 Jul 2004, 19:17

Postby LuckMan212 » Mon, 28 Nov 2005, 00:10

can this also apply to the 'full' nnCron?
also in the above code sample from Nicholas, the following line
Code: Select all
RUN-YOUR-PROG
I assume there you replace with something else but can a real actual example be shown? I am not sure what to put there
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby Valery_Kondakoff » Mon, 28 Nov 2005, 10:32

Hmmm. There are much easier ways to do the same with the 'full' nnCron. Just use the 'SCREENSAVER-ON?' word to chek if screensaver is running. Alternatively you can use 'PROC-EXIST:' word to check if the screensaver process is currently launched.
CU
VK
User avatar
Valery_Kondakoff
Site Admin
 
Posts: 769
Joined: Thu, 01 Jul 2004, 20:49
Location: Moscow, Russia


Return to nnCron forum (English)

Who is online

Users browsing this forum: No registered users and 1 guest

cron