Run a Script before shutdown or reboot windows 7

-1

I need a registry entry to a run once script at shutdown or reboot. I needs cleanup sensitive data after an installation. So even if the installation failed or got interrupted, i may not leave data behind.

The system cant make use of a group policy. And also i cant put something in the end in my other software-install script. So in the software-instal script i cannt put in shutdown command.

So it really comes down to some kind of shutdown runonce registry key.

user338847

Posted 2014-07-08T08:51:05.593

Reputation: 39

What version of Windows 7 are you using? Your question doesn't state (could you update this for us?)... – Kinnectus – 2014-07-08T15:38:50.807

Answers

0

This is not possible at shutdown. The only method of shutdown scripts is through group policy.

The only option is to run it at the next reboot. The registry key for that is this:

HKLM\Software\Microsoft\Windows\Current Version\RunOnce

You can replace HKLM with HKCU (current user instead of local machine) but this will only run if the current user is logged in, whereas LM will run for every user. Using LM will require adminstrative rights, whereas CU does not. So if you want to write to the LM subtree, your program has to run with administrative privileges.

LPChip

Posted 2014-07-08T08:51:05.593

Reputation: 42 190

1This isn't correct. Windows 7 is fully capable of running a shut down script through Local Group Policy. – joeqwerty – 2014-07-08T15:35:35.517

Yes, and that is exactly what I wrote. I say this is not possible at shutdown, because he states he doesn't want to use group policy. – LPChip – 2014-07-08T21:05:37.703

My bad. I assumed that you were both referring to domain Group Policy, not local Group Policy. – joeqwerty – 2014-07-08T21:18:12.713

-1

Windows 7 is fully capable of running a shutdown script through Local Group Policy.

joeqwerty

Posted 2014-07-08T08:51:05.593

Reputation: 5 259

He doesn't want to use that. He's developing software that he wants to redistribute and he doesn't want to rely on a local group policy. – LPChip – 2014-07-08T21:06:44.347