Problem in opening an application after cancelling shutdown!
Hi all,
I have an application written in vb6 which resides in system tray and open up another exe (say notepad for eg.) when we click on tray icon. It also track system shutdown, cancel shutdown and open up 'notepad' and wait till 'notepad' to close to continue with shutdown. This application runs perfectly in win9x but not in xp or other os.
This is what I'm doing:
In query_unload event, it tracks whether it is a system shutdown (using unloadmode) if it is, then cancels it and open notepad with shell command. Using the return id of shell command it gets the process exitcode and waits till that exitcode not equal to zero. Once it is zero, the program does the shutdown.
I tried shell_execute api and createProcess api as well instead of shell command. but with no luck. It never opens up a notepad when it is a shutdown event eventhough it cancels that event.
Is it due to any privilege issue? Actually it is a pc which I logs in as administrator.
Does anybody faced this type of a situation. Any comments are so appreciable.
Thanks & Regards,
Loks.
[1155 byte] By [
lokeshrao] at [2007-11-11 10:04:59]

# 1 Re: Problem in opening an application after cancelling shutdown!
What's your method to cancel shutdown ? I guess u call the winlogon.exe , right ?
I think it's better to make this with shutdown.exe , it has a simple command argument "-a" that abord shutdown .. the benifit of using the shutdown.exe call that is catching the shutdown process before stoping any windows services ..
***if u catch the windows shutdown when your application start unloading so u r in the first case when many windows services are already stopped , so I guess from here you got this problem .
Amahdy at 2007-11-11 17:23:15 >

# 2 Re: Problem in opening an application after cancelling shutdown!
Hi,
Thanks for the reply.
I don't use a shutdown.exe or anything like that becuase I suspect that may not work in win9x series. So I put something like this in queryunload event.
Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = vbAppWindows then
cancel = not cancel
RetId = shell("notepad",vbNormalFocus)
--Wait for notepad to close-- or --sleep(10seconds)--
unload me
set form1 = nothing
EndIf
End Sub
You can see that it never opens up a notepad, but closes the app after 10seconds. if u try to display the 'RetId' in a msgbox u will get one.
I even tried hooking the actual windows messaging using 'CallWindowProc' and 'SetWindowLong' apis. It does the same like the above code.
Is this is the actual way to cancel a windows shutdown or is there any other way to achieve it?
Any clue will be really helpful for me.
Regards,
Loks.
# 3 Re: Problem in opening an application after cancelling shutdown!
As I told u I think your method to catch the shutdowen is the problem coz when the windows want to stop your application , it has already stoped many services and one of them the srvice to open notepad .
I mean : when request sent to turn off windows then windows do >> end process >> end services >> end running progs ...
those three routines run at the same time and when u r in the unload event other services are in stop process .. so u can't open the notepad .
Amahdy at 2007-11-11 17:25:13 >

# 4 Re: Problem in opening an application after cancelling shutdown!
Hi,
That gave me a small hint. I'm able to do it now. I used the previous technique. Hooking the actual windows messaging using 'CallWindowProc' and 'SetWindowLong' apis with WM_QUERYENDSESSION. The mistake what I was doing was trying to open a notepad immedietly after cancelling. So i think it was trying to open a notepad before the OS receive the shutdown cancel request from my form and that always fails. Because the OS is ending the processess and services as u said. Now I just put a delay between the cancel shutdown request and opening the notepad using a timer thread and it works!. Thanks for the hint.