[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Shutdown problem with QueryUnload

Posted on 2002-03-14
6
Medium Priority
?
581 Views
Last Modified: 2008-02-01
I am trying to use the QueryUnload method to check to see if my application is ready for the system to shutdown.   However, it doesn't quite work correctly.   If when the QueryUnload method gets called and the subroutine cancels the shutdown, any future attempts to shutdown the system do not work.   And after the first shutdown gets aborted the QueryUnload method does not get called on later attempts to shutdown the system.  I am running Windows NT Server and I suspect that the real problem is being caused by some other application (or service) that is running on my system.

I've reproduced the problem with the following minimal project.

Project Type is specified as "ActiveX EXE"
Startup Object is "Sub Main"
Project contains one form (Form1), one module (Module1) and one class (Class1)

--- Form1 contains -----------------------------------

   Private Sub Form_QueryUnload(Cancel As Integer,
                                UnloadMode As Integer)
      If UnloadMode = vbAppWindows Then

          Cancel = MsgBox("Are you really, really sure you want to shutdown your PC?", vbYesNo) <> vbYes

      End If
    End Sub

--- Module1 contains --------------------------------

   Option Explicit
 
   Sub Main()
       Dim f As Form1
       Set f = New Form1
       f.Hide
   End Sub

--- Class1 contains --------------------------------

     'blank file
     'instancing is MultiUse
     'Persistable is NotPersistable


-----------------------------------------------------

Any help in finding this problem will be greatly appreciated.
0
Comment
Question by:JohnWeidner
6 Comments
 

Expert Comment

by:segan
ID: 6867299
Hi,

It seems really strange. Try to keep the 'f' as module level of sub Main. When you come out of Main, f may go out scope......

Selva.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6867581
Does this change anything:

--- Module1 contains --------------------------------

  Option Explicit
  private f as form1

  Sub Main()
      Set f = New Form1
      f.Hide
  End Sub

  Sub Done()
      set f = nothing
  End Sub

--- Form1 contains -----------------------------------

  Private Sub Form_QueryUnload(Cancel As Integer,
                               UnloadMode As Integer)
     If UnloadMode = vbAppWindows Then
        select case MsgBox("Are you really, really sure you want to shutdown your PC?", vbYesNo)
           case vbYes
             Done

           case vbNo
             Cancel = true  

         end select

     End If
   End Sub

...

Cheers
0
 

Author Comment

by:JohnWeidner
ID: 6877138
Selva and Angel,

Thanks for the suggestions.   However, they do not alter the behavior I am seeing.   I am getting more convinced that this is a problem with Windows NT (or some other service installed on my system.)   The program works fine on my laptop which runs Windows 2000.   Also, I've seen the same basic problem on this system if I try to shutdown and some other commercial program (like VB) interupts the shutdown to prompt for files to be saved.   If you click on cancel when propmted to save files, the shutdown gets aborted.   However, if you later try shutdown again, the system just sits there with the "dark" screen but no programs exit.

John
0
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.

 

Author Comment

by:JohnWeidner
ID: 6877379
This problem doesn't occur if I shutdown by pressing "Ctrl+Alt+Del" and then select "Shut Down" from the "Windows NT Security" dialog.   I'm thinking there is some Microsoft bug in the Explorer.exe shell.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7618316
Hi JohnWeidner,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

JohnWeidner, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Accepted Solution

by:
kodiakbear earned 0 total points
ID: 7665767
Moving to the paq

kb
Experts 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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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
Course of the Month19 days, 20 hours left to enroll

873 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