News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Safely terminate another process

Started by azdps, June 09, 2008, 06:23:56 AM

Previous topic - Next topic

azdps

It appears terminateprocess isn't really all that clean of a method to terminate a process. I saw a post on another forum by scronty http://www.asmcommunity.net/board/index.php?topic=229.0 which indicated a proper way to terminate a process would be to use the BroadcastSystemMessage function. I haven't seen any asm examples of this nor have seen much discusson about it. What would be the proper way to use the BroadcastSystemMessage function?

hutch--

If the app you want to shut down is designed to receice this message, it should work fine.


    WM_SHUTDOWN        = RegisterWindowMessage("close_my_app")

    SendMessage %HWND_BROADCAST,WM_SHUTDOWN,0,0

    process it in the WndProc with,

    Case WM_SHUTDOWN


Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

azdps

I've looked into the message WM_SHUTDOWN but I can't find any informaton on it. Can you explain this a little better please.

sinsi

What sort of process? Usually sending WM_CLOSE to the main window will be enough.
Or are you trying to force an app to close?

The trouble with BroadcastSystemMessage seems to be that it's not selective - it's a broadcast, so every app receives it (and/or driver, etc.)
Light travels faster than sound, that's why some people seem bright until you hear them.

hutch--

azdps,

Look at the API that defined the message, WM_SHUTDOWN is the variable for the return value of RegisterWindowMessage(), thats why you can't find the name. If BOTH apps register the same message then using SendMessage with the HWND_BROADCAST value for the handle and the defined message, one app can communicate with another by this method.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

azdps

Quote from: sinsi on June 14, 2008, 05:40:38 AM
What sort of process? Usually sending WM_CLOSE to the main window will be enough.
Or are you trying to force an app to close?

To clarify, my application needs to terminate explorer.exe, then immediately afterwards it will restart it. By shutting down and restarting explorer.exe someone using the application won't need to restart the computer. I have it setup right now using terminateprocess which works fine but I don't like the fact that it can create system stability issues.


Quote from: hutch-- on June 14, 2008, 12:53:09 PM
Look at the API that defined the message, WM_SHUTDOWN is the variable for the return value of RegisterWindowMessage(), thats why you can't find the name. If BOTH apps register the same message then using SendMessage with the HWND_BROADCAST value for the handle and the defined message, one app can communicate with another by this method.

what I don't understand now is how can I get the explorer.exe process to regster the same message.

hutch--

> what I don't understand now is how can I get the explorer.exe process to regster the same message.

You can't so I would be inclined to keep using the method you are already using.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php