Link to home
Start Free TrialLog in
Avatar of LanMan6401
LanMan6401

asked on

Simple VBS to exit a program correctly.

I need to have a few workstations logoff after 5m of idle time.  I plan on doing this with schedule tasks.  I need a VBS to exit a program properly.  Its a client that connects to a database, I don't want to force logoff and crash the client out each time since the client itself is based on access and doesn't like being forced to close.  The program uses ALT-X to exit each screen, a user can go as deep as 5-7 screens.  I think i need a script that would press ALT-X in this program untill it shutsdown.

Is this something thats easy to do?  I've used some VBS scripts before but I've never written one.

Thanks for any help !
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
LanMan6401,

What that will do is keep looping as long as there are running instances of Access, as it finds them, it shuts them
down in turn.  The loop terminates when the syb cannot find any open instances of Access.

Regards,

Patrick
Avatar of LanMan6401
LanMan6401

ASKER

Is this like "end tasking" access?  We have had problems with corruption before, I want to be sure it gets shutdown clean.
It should be akin to quitting Access from within the UI.

You can use something like AutoIT to actually simulate keypresses.

If you call a quit method, wether from a compiled program, or with a script command (which in turn uses WMI) you are essentially pressing the "exit" button (if the application has one). None of these commands do anything other than send an end-application message to the running application.   IF the application was coded to treat these messages kindly, it will cycle through open tasks and close them. Most applications (read all) are not written to respond to these messages in this way.

Check out :

http://www.hiddensoft.com/AutoIt/

This utility creates scripts that can send keystrokes (also mouse-clicks / etc), you can also use another piece of the software to compile these scripts into an executable that can be run on a target machine (to protect the content of the script from being changed by the end user).

They have many many examples and the support/forums are pretty good.
You can also send a window close, force=false message to the window which will not terminate it but instead ask it to shutdown:
https://www.experts-exchange.com/questions/10018555/Closing-A-Program-window.html?query=wm_close&topics=93

The problem with sending an application a wm_close message is that it will not do anything to it's internal screens/menus/etc. This is the -exact- same message as the end-task function from the task-manager (which is why this function/message exists, the task-manager uses it).

A good example is a terminal emulation application. This is simply a pass-through for a mainframe session, simply closing a window does not log the session off, it leaves it open and orphaned and leaves the user unable to connect until the session is terminated by an Admin.

If there is a requirement to actually "step out of" each window in the application, then some form of keypress emulation will be required.
Not true... it sends the unload request and any properly written program will close the session before terminating...
This doesnt just kill the process it asks the program to close but if he doesnt like that then he can try my other suggestion
LanMan6401,

What is your current status on this?

Patrick
agreed! You have our recomendations we're waiting to hear from you...
Sorry for the late response.  I was buried in a different project and now back on this one. :)

The first response from matthewspatrick is working great.

Thanks for the other responses as well.  I have heard of AutoIT and at sometime would like to delve into further but havn't had a need to yet.  

Thanks again!