Sign in to follow this  
Followers 0
JerryD

Is there such a thing as a Shutdown signal?

7 posts in this topic

Hi,

I'm using a nifty little menu program called PStart (http://www.pegtop.de/start/) as a menu system for a USB key and apps set up on it.

Anyway, aside from standard menu capability, you can set up an app to run when you exit the menu system.

I've written an AutoIt script to scan all running applications to see if any are still running from the USB Key's drive, and terminate them (ProcessClose) for all that are (except the script itself and the menu program).

It works fine, but rather than just slamming the door closed on these apps, I'd like to get them to terminate gracefully if possible.

Now when you try to shutdown and you have Word or Notepad open with an unsaved file, you get a warning. I figure that there must be something the shutdown process is doing to signal the applications to exit rather than just killing them.

I assume that's done through a DLL call, but regardless, does anyone know how to do that?

PART 2: While I've got your attention, one other thing. The SysInternals utility Handle can tell you all the files a specific process has open. I'd love to be able to do that and terminate processes that have files open on the USB key. Any hint would be of help.

Thanks!

Share this post


Link to post
Share on other sites



...Now when you try to shutdown and you have Word or Notepad open with an unsaved file, you get a warning. I figure that there must be something the shutdown process is doing to signal the applications to exit rather than just killing them...

Maybe WinClose:

Remarks

This function sends a close message to a window, the result depends on the window (it may ask to save data, etc.). To force a window to close, use the WinKill function. If multiple windows match the criteria, the window that was most recently active is closed.


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Maybe WinClose:

Great idea!

However, WinClose needs the window title. Ignoring whether or not a window is actually visible, how do I get the Window title from the info returned by ProcessList [PID and Process Name]? I looked around and couldn't (easily) find how.

Share this post


Link to post
Share on other sites

Great idea!

However, WinClose needs the window title. Ignoring whether or not a window is actually visible, how do I get the Window title from the info returned by ProcessList [PID and Process Name]? I looked around and couldn't (easily) find how.

try this:

http://www.autoitscript.com/forum/index.ph...st&p=232243

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

did you manage to solve this one JerryD?

It'd be cool if you can post your code.


Eagles may soar, but weasels don't get sucked into jet engines.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

You could use either:

WinClose ( "title" [, "text"] )

Remarks

This function sends a close message to a window (it may ask to save data, etc.).

WinKill ( "title" [, "text"] )

Remarks

WinKill will forcibly terminate the window if it doesn't close quickly enough.

Although WinKill can work on both minimized and hidden windows, some windows (notably explorer windows) can only be terminated using WinClose.

or ProcessClose ( "process" ), which you already know

In regards to part 2: I personally don't know of a way to duplicate that using autoit, but maybe one of the veterans do. Edit: Maybe this is what you are looking for:

Window Handles / HWNDs

The variant datatype in AutoIt natively supports window handles (HWNDs). A window handle is a special value that windows assigns to a window each time it is created. When you have a handle you may use it in place of the title parameter in any of the function calls that use the title/text convention. The advantage of using window handles is that if you have multiple copies of an application open - which have the same title/text - you can uniquely identify them when using handles. When you use a window handle for the title parameter then the text parameter is completely ignored.

Various functions such as WinGetHandle, WinList and GUICreate return these handles. It is important to note that a window handle is not classed as a number or string - it is it's own special type.

Note: Window handles will work no matter what WinTitleMatchMode is currently in use.

Example

$handle = WinGetHandle("Untitled - Notepad", "")

WinClose($handle)

Edited by Sorian

Share this post


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
Sign in to follow this  
Followers 0