Freezing Programs using Win32 Threads

This is a discussion on Freezing Programs using Win32 Threads within the Windows Programming forums, part of the Platform Specific Boards category; My friend developed a tutorial on how to use Win32 API Threads to Freeze Programs . Care to give it ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    137

    Freezing Programs using Win32 Threads

    My friend developed a tutorial on how to use Win32 API Threads to Freeze Programs.

    Care to give it a review perhaps?

    It could be a fun prank idea if you were to freeze your friends computer and then use some magic key to unfreeze it hehehe.
    ★ Inferno provides Programming Tutorials in a variety of languages. Join our Programming Forums. ★

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Freezing Programs using Win32 Threads
    First thing that came to mind was: Yeah, my Windows machine has this functionality built in...

    Aside from the sarcasm, it might be noted that privileges are still in effect. If notepad.exe is running with admin privileges, and the freezer is not, notepad won't freeze, of course.

    And for grins and giggles, rename the freezer to notepad.exe, or change the name of the app it is freezing to the freezer's name.

    Interesting piece of code otherwise. You might go a bit more in depth into the specific APIs, and what other (perhaps useful?) purposes they might hold - how you got the process information, for example, and what other useful information you can glean about a process/thread that way. What other stuff I can do to threads (you do a bit of this at the end of the article). Esp the process API - a lot of neat info can be found there. Basically, write something that makes me as a programmer want to fire up an editor and try it.

    It could be a fun prank idea if you were to freeze your friends computer and then use some magic key to unfreeze it hehehe.
    I'd be terribly amused...
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    137
    Apparently, he has just discovered Win32 api.
    Tell him to read the Petzold, Richter and Russinovich...

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,854
    I dislike the topic of the tutorial. You could have shown some harmless use.

    That code would be unacceptable if produced in my team for the following reasons;

    There is no error checking nor logging/notification.
    (If you are teaching people to code, teach them how to find and fix errors and write safe code.
    Try to create apps that gracefully handle errors, log them and recover if possible.)

    There are no comments.
    (When I write code I know exactly what the code does and why I do certain things.
    Next person to work on it won't. I don't remember my own code in 3-6 months, I work on too many varied systems.
    You must assume your students don't know what each line does and why you are doing it.)

    [Used K&R style indentation] (just my opinion)
    (I hate the leading brace on the same line style you use.
    I prefer the Allman style.
    It groups/aligns nested code and is more logical for new coders.)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    I honestly see little difference between K&R and allman , at leastr according to wikipedia. I always though K&R started the openming brace on the first line, not after it, but according to wiki I prefer banner style, although i never called it such and such a style, its just 'my style'.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  6. #6
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by novacain View Post
    There is no error checking nor logging/notification.
    (If you are teaching people to code, teach them how to find and fix errors and write safe code.
    Try to create apps that gracefully handle errors, log them and recover if possible.)
    It should have done an error check on OpenThread since that could return ACCESS_DENIED on some systems. But other functions can practically only fail if the system is running out of memory or some malware has broken the system.

    Quote Originally Posted by novacain View Post
    There are no comments.
    (When I write code I know exactly what the code does and why I do certain things.
    Next person to work on it won't. I don't remember my own code in 3-6 months, I work on too many varied systems.
    You must assume your students don't know what each line does and why you are doing it.)
    I agree that code should generally have comments, but in that case, most lines include a call to an API function that makes the code self-explanatory so comments would look funny there.

    Quote Originally Posted by novacain View Post
    [Used K&R style indentation] (just my opinion)
    (I hate the leading brace on the same line style you use.
    I prefer the Allman style.
    It groups/aligns nested code and is more logical for new coders.)
    Don't be subjective.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,169
    K&R puts the { on the same line as the conditional statement, while Allman puts all of them on a new row.
    I also like Allman and like K&R less, and absolutely detest the Banner style since it puts the ending } on the wrong level of indentation.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,854
    Remember this is a basic tutorial, not designed for experienced coders.

    Quote Originally Posted by maxorator View Post
    It should have done an error check on OpenThread since that could return ACCESS_DENIED on some systems. But other functions can practically only fail if the system is running out of memory or some malware has broken the system.
    Many other API functions can fail, it is not good practice to trust them. I have seen many apps where 'safe' API calls fail due to trashed memory.

    In this case, apart from the OpenThread();

    CreateToolhelp32Snapshot() could return an invalid handle and the app would not notice.

    Process32Next() could fail if the process has terminated during execution, stopping the app before it finds the right process to pause.

    ResumeThread() / PauseThread() will fail if the required access rights have not been specified.


    Quote Originally Posted by maxorator View Post
    I agree that code should generally have comments, but in that case, most lines include a call to an API function that makes the code self-explanatory so comments would look funny there.
    What about the flags used, why that one?
    What about the NULLs used, why don't we fill these in?
    etc.

    Quote Originally Posted by maxorator View Post
    Don't be subjective.
    I did clearly point out it was an opinion.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Beyond the previous comments:
    If you must do this sort of thing, at least make sure that once you have located the thread/process you want to operate on, you remember it's handle, rather than doing another search based on the name. If for some reason you start a second notepad in the 7 seconds that the first one is frozen, and it happens to end up before the one you found in the first case, you will unfreeze another process.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,534
    If I where to do this, I would probably get debugging privs, "debug" and hook the application, then evoke an special exception. I know that might be more work, but at least the operating system would be the one freezing the treads; I think it would safer that way.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Yet another n00b in pthreads ...
    By dimis in forum C++ Programming
    Replies: 14
    Last Post: 04-07-2008, 12:43 AM
  2. Replies: 0
    Last Post: 10-06-2007, 01:25 PM
  3. Win32 API or Win32 SDK?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-20-2005, 03:26 PM
  4. Way to get the current open programs displayed?
    By CPPguy1111 in forum C++ Programming
    Replies: 6
    Last Post: 06-22-2005, 12:24 AM
  5. Block and wake up certain threads
    By Spark in forum C Programming
    Replies: 9
    Last Post: 06-01-2002, 03:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21