3

This is almost the same as How to schedule a task to run when shutting down windows, except I need to do it programmatically. Also, I need the guarantee that when the script is run, no application can cancel the shutdown anymore.

Is this possible?

Thanks.

Update, with a little context: My company develops a sort of an antivirus program, designed to protect internet banking costumers. Naturally, this program is a frequent target of malware, so it needs to defend itself against being uninstalled. The first thing it does is inject itself into a system process, so that it can't be killed without bringing the whole system with it.

One of the typical ways of uninstalling such a program would be marking it for removal at the next shutdown, so our app actively monitors the registry keys which handle these postponed deletes and removes them.

I have recently been tasked with writing - oh the irony - an uninstaller for our app. The uninstaller must, of course, delete the files, so it has to work around everything we ourselves have built. It must be compatible with legacy versions, so changing the protection mechanisms is not an option.

Community
  • 1
  • 1
Pedro d'Aquino
  • 5,130
  • 6
  • 36
  • 46
  • 10
    Honestly though, you're running counter to how windows has been designed. Windows (especially as of windows 7) expects that every app script and service shuts down immediately or almost immediately when given the shutdown message. With windows 7, if things are running for even more than a second or two at shutdown time, the user gets the chance to force kill it. I'm not sure what you're trying to do, but making a task run at shutdown is probably not the way to do it. – Robert P Oct 11 '10 at 18:34
  • Windows 7 seems to perform some update tasks during shutdown, though the OS environment is probably pretty far gone by that point. What sort of tasks do you want to do with your script? – Nick T Oct 11 '10 at 19:45
  • @Robert, Nick: added some context on the question. Thanks for your time. – Pedro d'Aquino Oct 11 '10 at 19:58

1 Answers1

2

Since you need to support legacy versions that have no option of adding a backdoor for future use, you will likely have to boot the machine into an alternative OS so your files do not get loaded at bootup, then you can delete them safely. Look into incorporating a freeware third-party DOS clone, or even a small Linux version, into your uninstall process.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770