Solved

Terminating a screensaver..

Posted on 1997-11-14
8
313 Views
Last Modified: 2010-04-04
Hello,

Is it possible to detect if a screensaver is running ?
and if it is running can i terminate it even if it has an password ?

Procedure TNoteBoxMain.BreakScreenSaver;
Var
  Point: TPoint;
  WHandle: THandle;
Begin
  With Point do Begin X:= 16; Y:= 16; end;
  WHandle:= WindowFromPoint(Point);
  SendMessage(WHandle,WM_MBUTTONDOWN,0,255);
End;

this procedure terminates a screensaver with no password, but is has no detecting if a screensav is running
and when then screensav has a password it show the dialog box to enter the password.

Any help would be appreciated..
0
Comment
Question by:mories
  • 5
  • 2
8 Comments
 
LVL 1

Expert Comment

by:mortenmo
Comment Utility
Yep.. When you have password set it will always prompt on
a normal attempt to close the program..

However you can kill the program brutally (and therefor skip the
password part even if it is set)..

Use this SendMessage line instead:

 SendMessage(WHandle,WM_DESTROY,0,0);

Hope this helps..
0
 
LVL 1

Author Comment

by:mories
Comment Utility
But what if i don't know the handle of the screensaver i don't even know what and if a screensaver is installed...
0
 
LVL 1

Expert Comment

by:mortenmo
Comment Utility

Ups forgot that.. Here is what you can do..
 
--------
  SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, @dummy, 0);

  if dummy = 0 then begin
    With Point do Begin X:= 16; Y:= 16; end;
    WHandle:= WindowFromPoint(Point);
    Debug.Text := 'Screensave destroyed';
    SendMessage(WHandle,WM_DESTROY,0,0);
  end else
    Debug.Text := 'No screensaver';
-------

SystemParametersInfo(SPI_GETSCREENSAVEACTIVE,.. returns 0 if there is a screensaver currently running and 1 if there is no
screen saver running..

0
 
LVL 1

Expert Comment

by:mortenmo
Comment Utility
You can use TerminateProcess(WHandle) too tho..

But of course you should try to close it nicely first..
SendMessage(WHandle, WM_CLOSE, 0, 0); will ask it to die, but
if a password is set it wont close. Then you should send
WM_DESTROY

0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

by:mories
Comment Utility
I think this one is not very easy,

this SPI_GETSCREENSAVEACTIVE only looks if a screensaver is configured, it doesn't check if the screensaver is running.

you can test it if you put this in an OnClick event.

I hope this one can be solved.
0
 
LVL 1

Expert Comment

by:mortenmo
Comment Utility
Hmm.. Well since the screensaver always is the highest window
I guess this should work if you don't want to use
the point hack.

----------------
if dummy = 0 then begin
  WHandle := GetTopWindow(0);
  Debug.Text := 'Screensave destroyed';
  SendMessage(WHandle,WM_DESTROY,0,0);
end else
  Debug.Text := 'No screensaver';
end;
--------------------------
0
 
LVL 1

Expert Comment

by:mortenmo
Comment Utility
Are you sure?

I actually tried that SPI_GETSCREENSAVEACTIVE and it did return 0 when a screensaver were running and 1 if no were.

Lemme test some more..



0
 
LVL 2

Accepted Solution

by:
alona041797 earned 100 total points
Comment Utility
The window title of a screen saver is "Screen Saver". You can use FindWindow to locate its handle and whether or not it's running, and then destroy it.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now