Cool_Bhushan

Hi to all,

I want to write a program in vc++ which execute before Window shutdown. Is it possible, plz help me.

Is it possible to run a program before window shutdown

If yes then how is it possible.

Ur suggestion is valuable for me.

Thanks in advance.



Re: Visual C++ Language program to run before window shutdown?

Shakje

WM_QUERYENDSESSION and WM_ENDSESSION are sent when windows is shutting down. Create a service which just waits for these events, when it gets them run your code, or shell run another program.




Re: Visual C++ Language program to run before window shutdown?

Rocky

Thanks Shakje,

for ur reply.

Sorry to ask u again, Since i am new to VC++,

Can u plz tell me how to track WM_QUERYENDSESSION and WM_ENDSESSION

Actually I want to make program which store the system date and time in a database, when the system is going to turn-off.

Plz tell me how can I use ur suggestion in my application. Ur suggestion Help me lot.

Thanks in Advance,






Re: Visual C++ Language program to run before window shutdown?

Shakje

You need to either find out what events WM_QUERYENDSESSION and WM_ENDSESSION map to in .net, or, in Win32 trap the events in your wndproc. As for database entry you'll need a library that will write to a database (there's plenty of odbc stuff out there). If you're new to C++ this is quite a task (ie it's not something that can be done too quickly or easily) and I'd suggest reading a book or two on C++ before attempting it. You might also want to look into Win32 API (PSDK) and service programming.




Re: Visual C++ Language program to run before window shutdown?

Simple Samples

You might be able to get the information form the system event log and if so then that will be much easier. You can use WMI to read it. The event log has messages for start and stop of the log service.




Re: Visual C++ Language program to run before window shutdown?

Cool_Bhushan

Thanks

For ur suggestion





Re: Visual C++ Language program to run before window shutdown?

Shakje

It seems a bit silly to constantly be polling the event log, you could do this as easily as having a Win32 app that loops with a GetMessage (ie blocking until it gets a message), checks the message and if it's not one of the shutdown events returns to the main message pump. If it is, it runs some code, or runs a different program. Also I don't know when the event logging service stops, surely it's as the user logs off If he did it as a service there's no guarantee that it would still be running when the event log stores the event and if he did it as just an exe running in the background I doubt it even more.




Re: Visual C++ Language program to run before window shutdown?

Simple Samples

Shakje wrote:
It seems a bit silly to constantly be polling the event log

Yes it is silly. You are the one suggesting it; I did not suggest polling.

Shakje wrote:
you could do this as easily as having a Win32 app

If my suggestion satisfies requirements then it would be much easier than what you suggest. My suggestion could be implemented in about an hour using a sample script in the Microsoft Technet Script Center to start from. It could also be done using C++.