Solved

Simple VBS to exit a program correctly.

Posted on 2006-07-11
12
421 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
using Access 8 75
How to set the sa password in a vb6 code for sql connection 9 60
MS SQL Update query with connected table data 3 38
Problem to line 23 53
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…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

856 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