Avatar of joschramm
Flag for Germany asked on

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

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?
Windows OSWindows XPVisual Basic Classic

Avatar of undefined
Last Comment

8/22/2022 - Mon

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.

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

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!