Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Shutdown problem with QueryUnload

Posted on 2002-03-14
6
Medium Priority
?
578 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
[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
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
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.

 

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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

730 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