Solved

Simple VBS to exit a program correctly.

Posted on 2006-07-11
12
409 Views
Last Modified: 2012-05-05
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 !
0
Comment
Question by:LanMan6401
  • 4
  • 4
  • 2
  • +1
12 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
Comment Utility
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
 
LVL 92

Expert Comment

by:Patrick Matthews
Comment Utility
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
 
LVL 1

Author Comment

by:LanMan6401
Comment Utility
Is this like "end tasking" access?  We have had problems with corruption before, I want to be sure it gets shutdown clean.
0
 
LVL 92

Expert Comment

by:Patrick Matthews
Comment Utility
It should be akin to quitting Access from within the UI.
0
 
LVL 8

Expert Comment

by:Shakti109
Comment Utility

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
 
LVL 9

Expert Comment

by:justchat_1
Comment Utility
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 9

Expert Comment

by:justchat_1
Comment Utility
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
 
LVL 8

Expert Comment

by:Shakti109
Comment Utility

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
 
LVL 9

Expert Comment

by:justchat_1
Comment Utility
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
 
LVL 92

Expert Comment

by:Patrick Matthews
Comment Utility
LanMan6401,

What is your current status on this?

Patrick
0
 
LVL 9

Expert Comment

by:justchat_1
Comment Utility
agreed! You have our recomendations we're waiting to hear from you...
0
 
LVL 1

Author Comment

by:LanMan6401
Comment Utility
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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now