Solved

Simple VBS to exit a program correctly.

Posted on 2006-07-11
12
422 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
ID: 17085188
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
ID: 17085197
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
ID: 17087452
Is this like "end tasking" access?  We have had problems with corruption before, I want to be sure it gets shutdown clean.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

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

Expert Comment

by:Shakti109
ID: 17087605

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
ID: 17096483
0
 
LVL 9

Expert Comment

by:justchat_1
ID: 17096486
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
ID: 17104926

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
ID: 17105262
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
ID: 17105271
LanMan6401,

What is your current status on this?

Patrick
0
 
LVL 9

Expert Comment

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

Author Comment

by:LanMan6401
ID: 17290611
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How does CurrentUser work? 10 42
Collapse and expand table in Word 2010 2 103
Set WorkSheet  not Working 9 52
Remove Exif Orientation before adding image to db 9 42
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

726 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