Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 585
  • Last Modified:

Shutdown problem with QueryUnload

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
JohnWeidner
Asked:
JohnWeidner
1 Solution
 
seganCommented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
JohnWeidnerAuthor Commented:
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
JohnWeidnerAuthor Commented:
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
 
DanRollinsCommented:
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
 
kodiakbearCommented:
Moving to the paq

kb
Experts Exchange Moderator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now