Link to home
Start Free TrialLog in
Avatar of joschramm
joschrammFlag 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?
Avatar of vb_elmar
vb_elmar
Flag of Germany image

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.
8.zip
SOLUTION
Avatar of eemit
eemit
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4

Private Sub Form_Load()
    ExitWindowsEx EWX_SHUTDOWN Or EWX_FORCE = 4, 1
End Sub
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of joschramm

ASKER

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
Josef
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!

sincerly
Josef