vb6 app: "Can't quit" if XP tries to shut down

joschramm used Ask the Experts™
The Windows XP operation system tries to reboot my computer but cannot do so because my application "LeoLog" does not respond. XP produces the Message Box "Can't quit" (titled "LeoLog").
Since I wrote LeoLog in vb6 I know for shure that this Message Box is originated from XP.
As nobody is sitting before the computer there is no one to react on the message box and the computer will not reboot.
What can I do?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

If you know LeoLog's classname or title you can close the app before shutting down WinXP. Here is a function to kill an application :

Private Declare Function SendMessage Lib "user32" _
                                        Alias "SendMessageA" _
                                        (ByVal hwnd As Long, _
                                        ByVal wMsg As Long, _
                                        ByVal wParam As Long, _
                                        lParam As Any) _
                                        As Long

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_SYSCOMMAND = &H112
Private Const SC_CLOSE = &HF060

Private Const WM_CLOSE = &H10
Private Sub Form_Load()
    Dim h As Long
    h = FindWindow(vbNullString, "notepad") ' classname , windowtext
    MsgBox h
    If h > 0 Then
        Call PostMessage(h, WM_CLOSE, 0, 0)
    End If
End Sub

You don't know the "class name" and the "title text" of the "LeoLog" application?

-Then try this small "helper" program (see attachement) to retrieve the classname and the title.

Annotation: I coded the small program to help users who don't know the class name (and the window text) of their application.
Top Expert 2012
- Make sure there are no unfinished tasks before application closes:

- If it's not a window-less application:

Try to use a form's QueryUnload Event:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  If UnloadMode = vbAppWindows Then
      'This means the form is closing because the current Microsoft Windows operating environment session is ending
Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

This sample shuts the PC down. The "EWX_FORCE" parameter is important
because it ensures to close all open applications immediately.

Private Declare Function ExitWindowsEx Lib "USER32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

Const EWX_LOGOFF = 0
Const EWX_REBOOT = 2
Const EWX_FORCE = 4

Private Sub Form_Load()
    ExitWindowsEx EWX_SHUTDOWN Or EWX_FORCE = 4, 1
End Sub
This reboots the PC :

Private Sub Command1_Click()
    ExitWindowsEx EWX_REBOOT Or EWX_FORCE, 1
End Sub


Hi vb_elmar, eemit

many thanks so farr. Unfortunately I did not explain the situation enough. The facts are as follows:
On a remote computer LeoLog does do its work unattended (there is no user waiting to prompt any Message Boxes). The activity of LeoLog is watched by "LeoWatchdog". If LeoWatchdog notices that LeoLog is no longer alive it sends a SMS to the supervisior. The supervisor decides to reboot the remote computer by sending a SMS. If LeoLog has produced a message box (in worth case due to an unhandled runtime error) this reboot will never occur because the shutdown process issues a message box saying "program LeoLab does not react" or so (I do only know the german version) with to buttons ("stop immediately" and "cancel"). This message box will never be prompted!
One way to solve this situation would be that LeoWatchdog watches for the XP shutdown window (titled "Programm beenden - LeoLog") and than send vb_elmar's ExitWindowsEx

Any other suggestions?
Many thanks


Hi everybody,
Ifound this very simple solution:
registry path HKEY_CURRENT_USER\ControlPanel\Desktop
set AutoEndTasks  (REG_SZ) = 1
found at https://www.wintotal.de/tipparchiv/?rb=3010&id=492
Nevertheless your solutions are very helpful and created new ideas!


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial