CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1

    How to shutdown the XP system if my program is terminated by someone?

    When my program is running and if it is terminated (intentionally) via the Task Manager's Process tab, how can my program force a system shutdown or reboot?

    It would be better if there is sample code.

    Or are there alternatives to my problem?

    Thanks.
    Last edited by Kurosan; August 2nd, 2006 at 10:13 PM.

  2. #2
    Join Date
    Dec 2003
    Location
    Gods own country, India
    Posts
    248

    Re: How to shutdown the XP system if my program is terminated by someone?

    it is eqivalent to condition "you have lock your house door when you are not there " (forget the electronics methods) . A hidden(from taskman) monitor program may be the solution.

  3. #3
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: How to shutdown the XP system if my program is terminated by someone?

    You can have one more watch program, which Waits on process handle, You will also need to add handling of watching the 'watch' program from first one. You can have use multiple threads in first program to wait on watch program.
    Regards,
    Ramkrishna Pawar

  4. #4
    Join Date
    May 2005
    Posts
    4,954

    Re: How to shutdown the XP system if my program is terminated by someone?

    Look at this thread for sample.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  5. #5

    Re: How to shutdown the XP system if my program is terminated by someone?

    How would my program be notified that it's going to be terminated before shutting down or rebooting the system?

  6. #6
    Join Date
    May 2005
    Posts
    4,954

    Re: How to shutdown the XP system if my program is terminated by someone?

    Quote Originally Posted by Kurosan
    How would my program be notified that it's going to be terminated before shutting down or rebooting the system?
    Look at WM_QUERYENDSESSION message.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  7. #7
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: How to shutdown the XP system if my program is terminated by someone?

    Quote Originally Posted by Kurosan
    When my program is running and if it is terminated (intentionally) via the Task Manager's Process tab, how can my program force a system shutdown or reboot?
    Why would one want to restart the system should the user chooses to terminate one's application? I also presume that you would restart your application on system restart. Right?

    So, this requirement is as good as - "run my application or stop using your computer" - No?

    In general - ExitWindowsEx API does what you want i.e. shut down windows. Fortuntately, if someone chooses to kill your application via TM - there is little you can do about it. Perhaps, have another application that monitors this one... Or... Or... But, no clean way.

    Fortunately, so!
    Last edited by Siddhartha; August 3rd, 2006 at 03:22 AM.

  8. #8

    Re: How to shutdown the XP system if my program is terminated by someone?

    Quote Originally Posted by Siddhartha
    Why would one want to restart the system should the user chooses to terminate one's application? I also presume that you would restart your application on system restart. Right?

    So, this requirement is as good as - "run my application or stop using your computer" - No?

    In general - ExitWindows API does what you want i.e. restart windows. Fortuntately, if someone chooses to kill your application via TM - there is little you can do about it. Perhaps, have another application that monitors this one... Or... Or... But, no clean way.

    Fortunately, so!
    My program is supposed to prevent users from doing certain activities, so killing the program will circumvent the restrictions.

  9. #9
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: How to shutdown the XP system if my program is terminated by someone?

    Quote Originally Posted by Kurosan
    My program is supposed to prevent users from doing certain activities, so killing the program will circumvent the restrictions.
    What activities are these?

    Instead of shutting the computer down just because a user killed your application, you would rather start your application as a service with administrative privileges so that users who are not administrators will not be able to kill it.

    This in general would be a better way to doing things.
    Shutting Windows down in this situation is absolutely rude.

  10. #10
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: How to shutdown the XP system if my program is terminated by someone?

    Quote Originally Posted by Kurosan
    My program is supposed to prevent users from doing certain activities, so killing the program will circumvent the restrictions.
    Your program sounds malicious. Even if it's well-intentioned, it still could be used maliciously. Few here will help you.

  11. #11
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: How to shutdown the XP system if my program is terminated by someone?

    Quote Originally Posted by Siddhartha
    What activities are these?

    Instead of shutting the computer down just because a user killed your application, you would rather start your application as a service with administrative privileges so that users who are not administrators will not be able to kill it.

    This in general would be a better way to doing things.
    Shutting Windows down in this situation is absolutely rude.
    Agree to you Sid.

    OP should instead try using user policies and priviledge restrictions and/or firewall kind of thing.
    Regards,
    Ramkrishna Pawar

  12. #12
    Join Date
    Sep 2004
    Location
    New Delhi, India
    Posts
    640

    Re: How to shutdown the XP system if my program is terminated by someone?

    You can try these options instead of shutting down the system:

    1) Disable Alt + Ctrl + Del.

    2) Install a hook to see for Task Manager and then getting a pointer to the list control and emptying the process list.

    3) Hooking system functions like NtQuerySystemInformation.

    But, others are correct, forcing such things may not be what the user expects.
    "I rather not play football than wear Nerrazzuri shirt" - Paolo Maldini
    FORZA MILAN!!!

  13. #13

    Re: How to shutdown the XP system if my program is terminated by someone?

    Quote Originally Posted by Siddhartha
    What activities are these?

    Instead of shutting the computer down just because a user killed your application, you would rather start your application as a service with administrative privileges so that users who are not administrators will not be able to kill it.

    This in general would be a better way to doing things.
    Shutting Windows down in this situation is absolutely rude.
    Is this still workable as all the users in my company are logging onto their PCs with administrative rights?

  14. #14
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How to shutdown the XP system if my program is terminated by someone?

    Quote Originally Posted by Kurosan
    Is this still workable as all the users in my company are logging onto their PCs with administrative rights?
    If you are or have the blessing of the IT dept, you could create a policy for a service and only give domain admins permission to shut it down. Machine admins won't be able to shut the service down.

  15. #15
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: How to shutdown the XP system if my program is terminated by someone?

    Quote Originally Posted by Kurosan
    My program is supposed to prevent users from doing certain activities, so killing the program will circumvent the restrictions.
    I think you're missing the point that Sid and the others have already made. What right does your program have to restrict how people use their own computers? If they want to turn off the restrictions that your program imposed, they have every right to do so.

    Of course, if this was some kind of security device (let's say that it prevents them from accessing certain files or directories) the IT dept probably already has tools to handle the situation. If it doesn't, then you should think about writing a service that checks some kind of privileges before allowing the security to be breached. I don't think anyone will thank you for disabling their whole PC whenever they remove your program. As MikeAthon said earlier, your program sounds downright malicious.
    Last edited by John E; August 6th, 2006 at 01:13 PM.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured