Answer» Is there anyway in visual basic I can detect if the my PC is shutting down,is there any code I can use?I'd like my vb application to detect my computer's state,if it is shuting down,please I really need a very QUICK help,thanks for the time....Trying monitoring the SYSTEM event log. When event #1074 is posted, you'll know shutdown has begun.
Note: The actual event # may be different on various OSes. 1074 applies to XP.
Hope this helps. Yes I am using XP but how will I use it?What is the specific code to do?Sorry I am not yet familiar with such detection,please tell me how can I do it....Can you give a quick reply I have deadline this day so I really need to ACCOMPLISH this THING....Hoping for understanding...thanks.. You might define a Form_QueryUnload event to determine what is causing your application to shut down. A value of 2 means that the OS is shutting down. It's problematic what you would do with this piece of information.
You can ALSO do this with a simple VBScript:
Code: [Select] Set WshShell = CreateObject("WScript.Shell") n = 0 While n = 0 FoundShutdown = WshShell.AppActivate("System Shutdown") If FoundShutdown Then WScript.Echo "Shutdown started" End If WScript.Sleep 500 Wend
If you really want to go all out, you can use the WMI service to query the event log directly.
Let us know how you make out.
|