Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to halt all running programs

Posted on 1999-06-30
46
Medium Priority
?
401 Views
Last Modified: 2010-04-06
I am writing a program to avoid the kids use computer
too long time, force he/she have rest after a pre-defined   time.
The question is how to halt(pause?) all other current running applications when the pre-defined time arrived, only run my programs, when it finished, then resume
all other applications.

Rgds
sorry
0
Comment
Question by:sorry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 13
  • 11
  • 9
  • +3
46 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1385550
When the time has come up, fire up a screen-saver (perhaps one you write yourself) which is password protected. When the appropriate length of time has passed the program can turn off the screensaver, or (perhaps better) the screen saver can turn itself of.

Cheers,

Raymond.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1385551
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385552
You posted this question before, Right?

If you didn't get any response, it's because I think this cannot be done without trouble. Some applications my use vital resources. Those could be suspended too. Like games for example. Even shared DLL's could cause trouble.

Epsylon.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sorry
ID: 1385553
I have not post this question before, I only post a question how to check
the screensaver running or not and Madshi give a excellent answer.
Here my question is I want a play a interactive movie when the pre-defined time
passed, and it cannot solved by screensaver, the play movie program movie have
been done,
now question is how to  halt(pause?) all other current running applications and only run my applications, also all other applications should resumed when my application finished.

Why I want to do that because when my application standby (waiting for the pre-defined passing), the user may be using comptuer watching video CD or playing music/games eg. so have to pause them before my application run

Rgds

sorry
0
 
LVL 6

Accepted Solution

by:
Stuart_Johnson earned 800 total points
ID: 1385554
Unfortunately this can not be done.  The only way you could do it would be to close every single open application, but this could cause major problems (especially if you closed something that was required by the system).

The best I think that I could come up with in a situation like this would be:

1) Hide the task bar (at the bottom of the screen)
2) Disable Control-Escape
3) Disable Control-Alt-Delete
4) Disable Alt-Tab
5) Create a form which is maximized to conver the whole screen (a nice black on with no border, icons or title bar).
6) Run your application over the top of it

You could have a small program which is loaded at startup which counts down the time, and at a predefined interval, activates your program.

Would that be a workable idea for you?

Cheers,


Stuart.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1385555
Well, I would not say, it's not possible...

Stopping all other apps *IS* possible, but a bit dangerous. Pausing other apps is possible, too. But very dangerous. What IMO is not too dangerous is stopping all running apps that was started by the explorer - and perhaps the explorer itself. But then you can't of course simply resume them in exactly the same state as they were before you stopped them! You could only restart them. But I don't know if that would make sense. James, what do you think?

Regards, Madshi.
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 1385556
Madshi,

I didnt think this sort of thing was even remotely advisable and could introduce serious problems into the OS.  Especially if there where services relying on these application to be going all the time.

Imagine if you were in the middle of burning a CD, or a big download and every task was halted.  You would be pretty p**sedd of to say the least :)

I think in most instances, its safer to say it cant be done than to do something which could be dangerous.

Cheers,


Stuart.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1385557
Well, Stu, that's right. But generally I prefer to say, it *IS* possible, but of course it should be said that it is (or can be) quite dangerous...

Regards, Madshi.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385558
Well, do we agree then that it is 'not possible' without causing problems/danger?
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1385559
Well, it's dangerous, ok. We do not automatically cause problems, but we could perhaps cause problems. Though, sorry to say, you're wrong with shared DLLs. There are no shared DLLs in 32bit windows. Each process loads its own copy of the DLL into its memory/address context. So pausing/stopping application A has definetely no effect on application B, even if both use the same DLL. But I do agree, pausing/stopping unknown programs *is* dangerous (but possible).    :-)
0
 
LVL 4

Expert Comment

by:Radler
ID: 1385560
I've a componet that help you.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385561
Why not locking keyboard and mouse events instead of suspending? Just an idea.....
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 1385562
Sorry,

Further to my proposed answer, here is a skeleton application for you to start with.  It disables all the control keys (Ctrl-Alt-Del, Ctrl-Esc and Alt-Tab).  It draws a big black captionless window over everthing and then a final window set to 'Bring To Front' which you can work in.

I think you will find this is your best option.  Its none volatile :)

Cheers,

Stuart.
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 1385563
****.  I forgot the damn link :)

http://www.nlc.net.au/~enigma/source/disable.zip

See what you think.

Stu.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385564
That's no good. Unit2.pas is missing. Next to that it lock the whole system, does it...

And another problem:

How do you prevent this app from being killed itself? If you for example restart the system the app should restart too. It is easy enough for me to get rid of it. So I am afraid that we won't succeed.

And 'if' I could manage to write it I would sell it and not post it here, I think.

'Sorry', have you checked if there are already such apps available?

Epsylon.

0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 1385565
Hi Epsylon,

OK.  I added Unit2.pas into the archive and uploaded it again.  Sorry about that :)

How do you mean 'how do you prevent this app from being killed itself'?  How have you managed to kill it?

Stu.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385566
We want to write an app (let's call it 'Freezer') that at a certain time 'freezes' other apps so that can not be used at that time.
But if you are able to kill 'Freezer', what are we doing here then.....

Another example:

Configure Windows that you can only login with a password. Write an app called 'LogOffWindows' that at 10 pm automatically logs off (use ExitWindowEx API function). Now you will need the password to login again.
But if you manage to kill 'LogOffWindows' before that happens, the system will never be shutdown. Next to that the user can set the clock back at any time.

Just don't underestimate kids  :o)
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 1385567
Epsylon,

I still dont understand you.  I can not kill the application I have posted.  It locks out Ctrl-Alt-Del, the Windows Key, Windows-E, Windows-R, Windows-F, Alt-Tab, Alt-Esc.  You can not kill it (sort of pressing the reset switch).

As for the timer, thats easy to do.  I can write an app which you will not be able to detect running that will launch the other program.

All I need to know is:

A) How long do you want to set the timer before it freezes the system

B) How long do you want it to stay 'frozen' for?

I think what I have given you is probably the best thing so far to fake the suspension of all running applications.  Everything will stil happily run in the background until the program has finishe.

Can someone else please try what I have posted and see if they think it is right or not?  Especially 'sorry'.  I think what I have done is more than sufficent, and definately matches the requirements set in place by 'sorry'.  No mention was made for someone to write the actual timer part of the program, just the freezing part.  If 'sorry' wants that too, I can help with it.

Cheers,

Stuart.
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 1385568
Epsylon,

I just reread your last comments again and to be perfectly honest, there is going to be no way to prevent the kids from setting the clock to a different time.  The only think I can think of is if you saved the last time value in a variable, and then checked that the time elapsed is not too large.  If it is, then freeze the PC anyway.  This is very easy to do.

However, I think that logging in and out of the PC is an overkill.  As I mentioned to Madshi before, killing all other tasks could prove to be more of a pain in the butt than be benificial.  For instance, what happens if you are doing something which cant be forced to close (like Adaptec CD-Creator will not close if it is burning).  What I have suggested is going to be your best solution.

Cheers,

Stu.
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 1385569
Another thing we can do is to add the 'blanker' part of the program to the registry.  If it is terminated (by rebooting or turning off the PC), then is automatically restarted next time the PC is turned on.  If the user exists the program gracefully, then the registry entry is removed.

I think we are all getting completely confused here.  I would like to hear what 'Sorry' has to say about what we have been discussing.  After all, its his question.

Cheers,


Stuart.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385570
Stuart, I don't think Sorry wants to freeze the whole system....

There are enough utilities available to kill threads etc......

Look here for an existing application:

http://www.sarna.net/watchdog/index.shtml
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 1385571
Epsylon,

My application DOES NOT FREEZE THE WHOLE SYSTEM!  That is what I have been trying to say for the last 20 messages!  All mine does is sits in the FOREGROUND.  It draws a big ugly black window over everything else and prevents these other apps from becoming foreground applications.  I never once mentioned killing tasks.  Madshi suggested suspending all running applications and I went against that suggestion - hence this program.

Again, I would like to hear what Sorry has to say.  There is no point in us thrashing out a question when he is not around to give us any direction.  Our whole discussion has been completley guess work as none of us really know 100% what Sorry wants to do.

Best wishes,


Stuart.
0
 

Author Comment

by:sorry
ID: 1385572
Hi, Thank you all very much.

Here I explain a lot more detail about what I am doing and what I want to do:
I have a little brother only 9 years old, he fall into computer game completely,
he often play the games 4-5 hours without rest. So I am writing a program:
1. when computer start, it auto. loaded and  minimize to tray, start monitor how
   long time the computer has been used. If pass the pre-defined time (I define 45
   mins. for default), the program form will show on top and a cartoon stuff come out
   tell him he has play too long time, need have a break now, the cartoon stuff
   also show him how to do some exercises to relax (Turn head, finger stretch eg..)
   when the break time over (5 mins I defined for my brother), the program       minimized to tray and start monitor the computer usage again.
 
   I have finished the programing job for this part.

2. Problems come out now:  When I install the program into my little brother's
   computer, at first he is very happy, but soon he find if the programs come out
   when he playing games, he have a break following my program,but the game
   process still going on in background, he lost lots score when he finished break
   and resume the games. so he complain my program too stupid and make he
   lose in the game. I am very shame-making and promise him improve my program
 
   That why I want to halt other applications process and resume them after my       application finished.
 
   My real name is James, thank you all help me

Thanks & Rgds

James      
0
 

Author Comment

by:sorry
ID: 1385573
Hi, Thank you all very much.

Here I explain a lot more detail about what I am doing and what I want to do:
I have a little brother only 9 years old, he fall into computer game completely,
he often play the games 4-5 hours without rest. So I am writing a program:
1. when computer start, it auto. loaded and  minimize to tray, start monitor how
   long time the computer has been used. If pass the pre-defined time (I define 45
   mins. for default), the program form will show on top and a cartoon stuff come out
   tell him he has play too long time, need have a break now, the cartoon stuff
   also show him how to do some exercises to relax (Turn head, finger stretch eg..)
   when the break time over (5 mins I defined for my brother), the program       minimized to tray and start monitor the computer usage again.
 
   I have finished the programing job for this part.

2. Problems come out now:  When I install the program into my little brother's
   computer, at first he is very happy, but soon he find if the programs come out
   when he playing games, he have a break following my program,but the game
   process still going on in background, he lost lots score when he finished break
   and resume the games. so he complain my program too stupid and make he
   lose in the game. I am very shame-making and promise him improve my program
 
   That why I want to halt other applications process and resume them after my       application finished.
 
   My real name is James, thank you all help me

Thanks & Rgds

James      
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1385574
Well, James, you have chosen the by far most difficult solution. Normally you can't simply pause other applications. 32bit Windows is a real multitasking OS. That means that YOUR application can't tell the OS to get ALL CPU time. There is no API for that purpose (and there never will be).
Although Eps and Stu will probably complain again about what I will be saying next  :-)  I know of a possibility to pause other applications. But it is highly hacked and *VERY* dangerous. I tested it with notepad and it worked perfectly, but I don't know how a game will behave. So again: It is *VERY* dangerous. The solution is this: You can enumerate all running processes, find out which programs you want to pause. Then you can do the following for each program you want to pause:
(1) Enumerate all threads of the program.
(2) Suspend each thread.
That's all! After the 5 minutes are over you could again:
(3) Resume all threads of all programs you suspended.
Well, it doesn't look too hacked, does it? The real problem is that you need a thread handle to each thread you want to suspend/resume. But enumerating the threads only give you the threadID. And there is no API for getting a thread handle from the threadID (something like OpenThread). There IS an undocumented function for NT (called NtOpenThread), but none for win9x. So I thought about the problem some months ago and invented a very ugly hack. So if you are interested, give me your eMail address and I will send you my units. However, you MUST NOT use them for any commercial purpose!!! Only for your private! Ok? I'm not sure, but perhaps I will sell them someday.
My test sources that suspended notepad look like this:

var i1 : integer;
initialization
  with Process('notepad.exe') do begin
    with threads do
      for i1:=0 to ItemCount-1 do
        Items[i1].Suspend;
    MessageBox(0,'notepad suspended...','info',0);
    with threads do
      for i1:=0 to ItemCount-1 do
        Items[i1].Resume;
  end;
end.

Of course this works for win95,win95osr2,win98,winnt4 and win2000...   :-)

BTW, Eps, if you are interested in testing it yourself, simply use the winObj units I sent you some weeks/months ago...   :-)

Regards, Madshi.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1385575
Ahh. Yep, I *HAVE* your EMail address. Do you want it?
0
 

Author Comment

by:sorry
ID: 1385576
Hi, Madshi

I want it, please send it to me, I promise only use it
for private.

Rgds

James
0
 

Author Comment

by:sorry
ID: 1385577
Hi, I also have another problem in this case:
if the keyboard and mouse not active when the pre-defined
time point passed, should the program pop-up?
I think it is a difficult question,because you
don't what user doing at the moment, may be he is watching
movie use the computer, even he did not tough the keyboard
& mouse, the program also should pop-up and tell him should
have a break. but if you he leave away, not site in the front of the computer, then the programs should not pop-up,
keeping standby.

May be, when time point passed, pop-up a button let user
select continue or not, if user not press the conutinue
button within 1 mins, we assume he leave away for a while,
then minimize the program waitting for next time point.

I think it is the best solution i can find at the moment,
please kindly post your comment and suggestion!

Rgds

James
0
 

Author Comment

by:sorry
ID: 1385578
Hi, I also have another problem in this case:
if the keyboard and mouse not active when the pre-defined
time point passed, should the program pop-up?
I think it is a difficult question,because you
don't what user doing at the moment, may be he is watching
movie use the computer, even he did not tough the keyboard
& mouse, the program also should pop-up and tell him should
have a break. but if you he leave away, not site in the front of the computer, then the programs should not pop-up,
keeping standby.

May be, when time point passed, pop-up a button let user
select continue or not, if user not press the conutinue
button within 1 mins, we assume he leave away for a while,
then minimize the program waitting for next time point.

I think it is the best solution i can find at the moment,
please kindly post your comment and suggestion!

Rgds

James
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1385579
Ok, units are sent.

Well, you only know how to check the screen saver, right? So I think the best possibility is to stop your timer while the screen saver is running. Then you don't need to look at key and mouse yourself.

Regards, Madshi.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1385580
Forget this "only". I meant: "Well, you know how to check the screen saver..."
0
 

Author Comment

by:sorry
ID: 1385581
Hi, Madshi
I don't think so, keyboard & mouse not active does not mean
the screensaver running, just like what i said may be the user watching movie use the computer, he neednot tough any
keyboard & mouse, but my programs also should reminder him to have a rest if he watch movie too long time.

Rgds

James
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1385582
If the user watches a movie and presses no key for a long time, then the screen saver will start. Is that right?
If yes:
  The user will press a key, and your timer will continue running. That's right. Or the user will NOT press a key, then your timer stops. That's alright, too.
If not:
  Your timer won't stop at all. That's also right.

So I think everything is fine. If you don't think so, then please describe me, in which exact situation your program would behave wrong, and how it should behave.

Does the suspending work???

Regards, Madshi.
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 1385583
Madshi.

Could I review the code you posted to James?  If its cool, my email is enigma@nlc.net.au.

Thanks mate.


Stu.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1385584
No prob, Stu, units are coming...   :-)
0
 

Author Comment

by:sorry
ID: 1385585
Hi, Madshi,

May be you still not understand what I mean, i mean keyboard and mouse not
active has lots case, watch movie just one case.
A very often happened case is: if the user's disable screensaver in his computer,
he has a meeting and leave away from his computer, if my programs pop-up at this
time and tell he to have a break, it seems the program little bit stupid, because nobody sit in the front of computer at the moment.

so that why I think may be pop-up a continue button first before main program running is best solution, user can press continue to start main program following model to do some relax exercises, if he not there, then the program will auto. close if nobody press continue button within 1 mins.

What do you think? Madshi

Thanks

James
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1385586
Ok, but the problems are only there if the PC has no screen saver installed. The program is only for your brother, you said. Can't you make sure he has a screen saver installed?

Well, of course you can install a system wide hook (in a DLL) to watch for mouse and keyboard input. I think I gave you something to start with in the screen saver question. But that's not too easy...

Of course you can also do it the way you suggested...   :-)

Regards, Madshi.
0
 
LVL 4

Expert Comment

by:Radler
ID: 1385587
Post your email sorry.
I'll send a component, I'd like post it as an answer, but the question is locked :(.

0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385588
Radler, could you explain what you have or where you got it?
0
 

Author Comment

by:sorry
ID: 1385589
Hi, Ralder,
 Please kindly send your component to: konchjin@statoil.com

Rgds
James
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1385590
Hi James, did my or Radler's components help you?

Radler, how do your (?) component work?
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1385591
Stu, Eps, have you tested my suggestion?
0
 
LVL 4

Expert Comment

by:Radler
ID: 1385592
I Back;

My component make use of screen saver running arguments too,
the difference resides in a hide password protection and capture of the mouse and kbd events from user.
Anothers "frescuras" are a bitmap to represent the locked state of the machine.
I sent it to sorry and none feed back was given.

T++, Radler.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385593
Madshi, I have been so busy answering questions that I completely forgot about this question. I'll take a look at WinObj tomorrow. Maybe I'll even get new ideas. You'll never know  :o)
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1385594
James? Are you there???
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 1385595
Hi Madshi,

Like Eps, I have been flat out as well.  I'd forgotten about this question and hadn't given it another thought.  I'll try to look at it ASAP, but I dont know if it will be tomorrow.

Cheers,

Stu.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

688 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