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 !
LVL 1
LanMan6401Asked:
Who is Participating?
 
Patrick MatthewsConnect With a Mentor Commented:
Hi LanMan6401,

Rather than do that, how about something like:

Sub KillThatAccess()

    Dim accApp

    On Error Resume Next

    Do
        Set accApp = GetObject(, "Access.Application")
        If Err <> 0 Then Exit Do
        accApp.Quit
        Set accApp = Nothing
    Loop

End Sub

Regards,

Patrick
0
 
Patrick MatthewsCommented:
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
0
 
LanMan6401Author Commented:
Is this like "end tasking" access?  We have had problems with corruption before, I want to be sure it gets shutdown clean.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Patrick MatthewsCommented:
It should be akin to quitting Access from within the UI.
0
 
Shakti109Commented:

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.
0
 
justchat_1Commented:
You can also send a window close, force=false message to the window which will not terminate it but instead ask it to shutdown:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_10018555.html?query=wm_close&topics=93
0
 
Shakti109Commented:

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.
0
 
justchat_1Commented:
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
0
 
Patrick MatthewsCommented:
LanMan6401,

What is your current status on this?

Patrick
0
 
justchat_1Commented:
agreed! You have our recomendations we're waiting to hear from you...
0
 
LanMan6401Author Commented:
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!
0
All Courses

From novice to tech pro — start learning today.