Kaseya Community

How can I automatically run a script Post-Reboot?

This question is answered

Is there a way I can apply a script to run every time a machine is rebooted? How would I do this :)

Verified Answer
  • Don't forget to look for events for "unexpected system shutdown". Using the event log to queue the script, either  looking at an event that occurs as it is shutting down or one that appears at bootup, are probably the best ways to do this.

    Another method would involve having a .BAT file run at bootup in the Autorun section of the registry that creates an event log entry using eventcreate.exe that inserts something like ' "The system has just booted"' to an event log. You could queue off this event and it would be a pretty reliable method of running a script after a machine reboots.

All Replies
  • Yes but it will depend on your method of rebooting and also your Kaseya server version.

    K2 comes with pre/post procedure for Automatic Update under Patch Management.

    If you are just referring to reboots procedures then you add a schedule procedure/script line to occur 5-10-15min after the reboot script has run.

    You could also monitor for;

    • System Event ID 12 *The operating system started at system time*
    • System Event ID 13 *The operating system is shutting down at system time*

    (Source: Kernel-General, Type: Information) and Schedule a script when one of the above events occur.

  • Don't forget to look for events for "unexpected system shutdown". Using the event log to queue the script, either  looking at an event that occurs as it is shutting down or one that appears at bootup, are probably the best ways to do this.

    Another method would involve having a .BAT file run at bootup in the Autorun section of the registry that creates an event log entry using eventcreate.exe that inserts something like ' "The system has just booted"' to an event log. You could queue off this event and it would be a pretty reliable method of running a script after a machine reboots.

  • I did what Ben suggested and created an event to trigger off. Thanks Ben.

  • What's your use case for this one if you might enlighten us :)

  • I have a server that has to stop and restart several services on boot and do some stupid stuff with IIS application pools :(

  • Sound like your services dependency are a bit screwy