?
Solved

Urgent-Terminate my program when windows logoff/shutdown event occurs

Posted on 2003-03-29
8
Medium Priority
?
252 Views
Last Modified: 2010-05-01
Hi dudes

I have a program that sits in the background and waits for certain events to occur. The program works fine, only until the user tries to log off or shutdown the system. Whenever the logoff/shutdown event occurs, a message box pops up saying that "XY Program Not Responding .... End Now?". However I want to capture the logoff event in my program, so that I can end my program as soon as the logoff event is initiated.
An immediate help would be appreciated.

Thanks in advance
0
Comment
Question by:cool_dudeps
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 3

Expert Comment

by:DocM
ID: 8229893
Hi,
Check the value of the UnloadMode property in the Form_QueryUnload event.

From VB help:

The unloadmode argument returns the following values:

Constant  Value Description

vbFormControlMenu 0 The user chose the Close command from the Control menu on the form.

vbFormCode  1 The Unload statement is invoked from code.
vbAppWindows  2 The current Microsoft Windows operating environment session is ending.

vbAppTaskManager 3 The Microsoft Windows Task Manager is closing the application.

vbFormMDIForm  4 An MDI child form is closing because the MDI form is closing.
0
 
LVL 6

Expert Comment

by:VK
ID: 8229994
Perhaps he has no Form.
It could be (in the simplest form):

do while true
  '...some code here to detect the logoff-event
  DoEvents
loop

This should be done by subclassing the desktop window and catching the WM_CLOSE Message or someting like that.

0
 

Author Comment

by:cool_dudeps
ID: 8237481
Actually what I want is to set a very low priority of my application, so that the shutdown event forcibly terminates my program. Any suggestions????
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Expert Comment

by:wcwnet
ID: 8251497
Your app has something either looping with no way to exit the loop, if this is by design, place a variable in the loop for exit on certain condition, in the main form Exit put a line that sets the exit condition for your loop.
0
 
LVL 6

Expert Comment

by:VK
ID: 8251884
Hello cool_dudeps !

You always will get "App not responding" from windows if your app doesn't respond to an "system logoff"-event - even if you set the prority very low.

If you want to set the prioroty of your app very low you could use a timer (with form or not)where you execute the whole background task. Set a big Intervall for low priority.

Also it is suitable to execute a DoEvents statetment periodically if windows shouldn't get "App no responding".

An easy way:

Sub main()
    Load Form1
End Sub

Private Sub Form_Load()
    Timer1.Interval = 1000
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    DoEvents
    'Do what is to do in the Background
    DoEvents
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Select Case UnloadMode
        Case vbFormControlMenu
        Case vbFormCode
        Case vbAppWindows
            'Here you will get if system will be shut down
        Case vbAppTaskManager
        Case vbFormMDIForm
        Case vbFormOwner
    End Select
End Sub
0
 

Expert Comment

by:CleanupPing
ID: 8531371
Hi cool_dudeps,
This old question (QID 20567268) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 9440730
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

 -->PAQ - with points refunded

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer
0
 

Accepted Solution

by:
YensidMod earned 0 total points
ID: 9495580
This question is PAQed and no points refunded (of 50)

YensidMod
Expert Exchange Moderator
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…
Suggested Courses

765 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