Click here to Skip to main content
15,896,727 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi there,

i have one folder with name (Data) on C Drive.

i want folder backup on D Drive before shutdown or restart. when i give shutdown then software automatically create folder (Data) on D Drive, if Folder is already exist then it ask about over right. can any body help me..?


Posted

1 solution

This can be done using the class Microsoft.Win32.SystemEvents. Please see:
http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.aspx[^].

Pay attention for the static events Microsoft.Win32.SystemEvents.SessionEnding and Microsoft.Win32.SystemEvents.SessionEnding. You add a event handle to any of them, check up the reason of ending, which is passed to you in event arguments, and perform the action before the session actually ends. Interestingly and importantly, in case if SessionEnding you can even cancel the ending, which will effectively delay shutdown or restart until the user allows to forcefully shutdown or restart it either by ignoring your application or checking if it's safe to end the session. Please see:
http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.sessionending.aspx[^],
http://msdn.microsoft.com/en-us/library/microsoft.win32.sessionendingeventargs.aspx[^],
http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.sessionended.aspx[^],
http://msdn.microsoft.com/en-us/library/microsoft.win32.sessionendedeventargs.aspx[^].

—SA
 
Share this answer
 
Comments
Abhinav S 11-Jul-12 23:31pm    
5!
Sergey Alexandrovich Kryukov 11-Jul-12 23:34pm    
Thank you, Abhinav.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900