Solved

Shutdown problem with QueryUnload

Posted on 2002-03-14
6
569 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 142

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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

774 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