Jump to content

Send shutdown command to an application?


Recommended Posts

Hello.

Is there a way send shutdown command to a running process?

There are many intercept shutdown scripts, so I wonder if there is a way fake shutdown message and send it only to a specific process?

The process in question has no window, but has tray icon without menu.

 

Thank you.

Link to post
Share on other sites
  • Developers

How have you determined that as this is simply a Windows message being send to the Window and is the way to tell the application to gracefully close?
It is not like ProcessClose() which actually does hard kill the task.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites

Well, when the application is killed via task manager or via winclose() the next time it started, it changes settings to default, when it closed gracefully via exit in tray menu (I lied about not having tray menu, because I don't want to use it), next time it launches it restores the settings.

This is what I've used:

Local $aProcessList = ProcessList("lcore.exe")
Local $aWinlist = Winlist()
For $i = 1 To $aProcessList[0][0]
    For $j = 1 To $aWinlist[0][0]
        If WinGetProcess($aWinlist[$j][1]) = $aProcessList[$i][1] Then
            ConsoleWrite("WinClose PID[" & $aProcessList[$i][1] & "] HWND[" & $aWinlist[$j][1] & "]: " & WinClose($aWinlist[$j][1]) & @CRLF)
        EndIf
    Next
Next
Edited by VAN0
Link to post
Share on other sites
  • Developers

Ok, so guess you have the same issue when you hit the X at the right top of the window? 
Anyways, it is the Application not handling this correctly so you probably need to send the Exit option message to the window with WinMenuSelectItem().

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites

It doesn't have any GUI window that can close the application, just tray icon.

The reason why I don't want use tray menu, is because sometimes the application is not responding to right click, I was hoping it's not completely frozen and can still receive and handle shutdown commands. When it "freezes" and than system goes into reboot the application starts normally with all settings restored, so my hypotheses it's still responding to system's shutdown message.

Edited by VAN0
Link to post
Share on other sites
  • Developers

Ok, so that external application still responds to the "Windows is shutting down" message but doesn't respond to the trayicon. 

You could try sending the .. to the app:

#include <WindowsConstants.au3>
$hWnd=WinGetHandle('your program window')
_SendMessage($hWnd, $WM_QUERYENDSESSION)

... maybe that works but haven't tested it.

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites
  • Developers

Tested this on SciTE and seems to be working fine:

#include <SendMessage.au3>
#include <WindowsConstants.au3>
$hWnd=WinGetHandle('[CLASS:SciTEWindow]')
_SendMessage($hWnd, $WM_QUERYENDSESSION)

 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...