I want to commit the chages/ want to do some activity on service's OnShutuDown().B ut i found that It neven get's called ..when i shut down the system or when i power it off..
On the contrary - OnShutDown() (when spelled correctly) gets called when the services is requested to stop. If it's not being called then something is stopping your service from closing down in a timely manner. I couldn't begin to hazard a guess at what that is without seeing any code.
The only thing I can think of is when you shut the system down it's slightly different than when you tell the service to stop in the services applet, in that if the service doesn't stop within the specified time frame - I think the default is 1 minute...unless you have Exchange Server installed and it is changed by default to 10 minutes (600000 milliseconds). Once this timeout occurs the service processes are terminated in an uncontrolled fashion, frequently their shutdown process isn't complete successfully, and in some cases the shutdown process isn't even started before the process is killed.
Sadly, I'm not sure if there's a way around this... maybe extend the timeout period to give your service more time to close. It requires a mod to the registry, so careful...
Here's the registry key:
HKEY_LOCAL_MACH INE\SYSTEM\Curr entControlSet\C ontrol\WaitToKi llServiceTimeou t
Just increase the value (remember, it's in milliseconds, so setting it to 60 thinking you're setting it to a minute won't help the situation). Of course, don't be shocked when it takes Windows longer to go down for a reboot.