You can do it using Task Scheduler:
- Right-click on the "Task Scheduler Library"
- Click "Create Task"
- For "Name:" field write Your new task's name.
- Check that the "Security options" area has checkboxes where You want them to be.
- Under "Triggers" tab click "New..."
- Select "Begin the task:" => "On an event"
- Select "Log:" => "Microsoft-Windows-NetworkProfile/Operational"
- Select "Source:" => "NetworkProfile"
- Write "Event ID:" => 10000
- OK this dialog.
- Under "Actions" tab click "New..."
- Select "Action:" => "Start a program"
- For "Program/script:" browse to Your favorite script file.
- OK this dialog.
- Setup the "Conditions" tab regarding "Idle", "AC power" etc conditions to Your liking.
- Also do setup under "Settings" tab.
- OK, all done here.
- Test the new event.
Just in case, there are also events for computer "Suspend" and "Resume" available there. I, for example, use them to stop and restart Hamachi on these events, since otherwise it seems to have problems on my machine.
For computer "Suspend" You can use Log "Microsoft-Windows-Kernel-Power/Thermal-Operational", Source "Kernel-Power" and the Event ID is 42.
For computer "Resume" You can use Log "System", Source "Power-Troubleshooter" and the Event ID is 1.
For user login/logoff, I do not know events under Task Scheduler (but I believe they are available there too), but You can configure it instead here:
- Launch gpedit.msc
- Open "User Configuration"
- Open "Windows Settings"
- Click "Scripts (Logon/Logoff)"
- In the right pane You can assign scripts for "Logon" and "Logoff" events. Note, if You assign multiple scripts then do not assume that they are run synchronously. They may not. For this case use single script instead, that calls other scripts in sequence. I haven't checked under which account these scripts run - is it user or system?
You can do similar stuff for computer "Startup" and "Shutdown" events under "Computer Configuration" folder in the same window. The Startup script runs under System account before the user logs on.