Do you want to do this just when your program is running, but restore everything when your program ends?

Why do you have this particular need?