Solved

Shutdown problem with QueryUnload

Posted on 2002-03-14
6
563 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now