Restart a windows service when hard drive is attached

I’m looking for a way to automatically restart a service in windows when a hard drive is attached. It’s an ISCSI disk which comes online shortly after windows starts but the service loads first and needs to be restarted after the disk comes online.

I could probably just have the service restart after a few seconds but I was wondering is anyone knows a way to have it triggered by the disk coming online.

Thanks

Does task scheduler have the required options? At least you should be able to delay the service start from there, or is the drive mounted, unmounted, mounted etc so that the service should run whenever the drive comes online, not just once at startup?

I set it up as a scheduled task to run on startup after a delay, but I don’t know how to run it after the disk connects. It doesn’t really matter, I’d just prefer it to be triggered by the disk and not just a timer.

You can try scheduling a task that’s triggered from an event. You can see in the event viewer if any event comes up when the disk gets online and use that event’s ID as a trigger for the task.

I’ve never tried it, but… why not use autorun functionality for this?

1 Like

Is there an easy way to figure out which events are tied to the disk? This happens at startup so there are a lot of events going on.

@dmj That might work, I’ll have a try