The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: azdps on June 09, 2008, 06:23:56 AM

Title: Safely terminate another process
Post by: azdps on June 09, 2008, 06:23:56 AM
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?
Title: Re: Safely terminate another process
Post by: hutch-- on June 09, 2008, 05:43:16 PM
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


Title: Re: Safely terminate another process
Post by: azdps on June 14, 2008, 05:29:15 AM
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.
Title: Re: Safely terminate another process
Post by: 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?

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.)
Title: Re: Safely terminate another process
Post by: hutch-- on June 14, 2008, 12:53:09 PM
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.
Title: Re: Safely terminate another process
Post by: azdps on June 14, 2008, 02:44:07 PM
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.
Title: Re: Safely terminate another process
Post by: hutch-- on June 15, 2008, 03:40:33 AM
> 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.