Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduled Task Shutdown #1

Closed
mtitheradge opened this issue Nov 13, 2014 · 11 comments
Closed

Scheduled Task Shutdown #1

mtitheradge opened this issue Nov 13, 2014 · 11 comments

Comments

@mtitheradge
Copy link

Hi,

I've been trying to set this up as a scheduled task to shutdown all PC's on our network at a certain time. There are 2 scenarios in the Task Scheduler:

  1. "Run whether the user is logged on or not" - PC's at the login screen shutdown without warning, which is perfectly fine but PC's which are logged in and being used also shutdown without warning.
  2. "Run only when user is logged on" - Users who are logged in have the option to postpone or abort the shutdown, but PC's at the login screen do not shutdown.

I don't know why the dialog box does not pop up when I set it to scenario 1. Is this a Microsoft issue or something which can be fixed?

@BobVul
Copy link
Owner

BobVul commented Nov 13, 2014

You've found an interesting case.

Your second option runs in what is known as interactive mode. It can display things to a user in an interactive logon session. That's simple enough, and was the case I originally considered when writing this.

Your first case... to be honest, I'm not sure what exactly it does beyond not requiring an interactive session. This program requires a message queue for the timer that eventually triggers the shutdown - and I wouldn't expect a message queue to exist without a logon session. So it probably creates its own session behind the scenes.

I don't think there's a supported way to hijack a session from a different one. The best that could be done would be a process that's constantly running in the background on every session, and the scheduled non-interactive process communicating with these processes.

Another option is to have one scheduled task for each case - one for the "no users logged in", and one for the "user is logged in". Need some way to detect there's no users logged in. A (rather ugly) way of doing that would be to use other tasks to enable the shutdown task on user log out, and disable it again on user log in. Another way to detect would be to have the logged in one run a little earlier, so the two can communicate (and the second won't run if the first is active).

Incidentally, do you have multiple users on the same machine? Seems like that would require you to create one task per user anyway.

@mtitheradge
Copy link
Author

Thank you for the quick response. I tried running the "logged in only" scheduled task follow by the "logged out or in" one shortly afterwards and the "logged out or in" one just shut me down without a warning or option to abort. I was logged in when both tasks started.

I will have to try using the "if computer is idle" option within the task scheduler to get the PC's at login screens, then have different tasks running at different times. I really appreciate your swift reply though.

Thanks

@BobVul
Copy link
Owner

BobVul commented Nov 13, 2014

Hm. Let me try something. It shouldn't be too hard to make sure they won't interfere with each other.

I ask again: do you have only a single user? Is there the chance that another user might log in (fast user switching)?

@mtitheradge
Copy link
Author

No user switching, each person logs off fully before another logs in.

@BobVul
Copy link
Owner

BobVul commented Nov 13, 2014

Well, that guarantee makes things easier. What I'm thinking now is to have an instance launch on user login, and stay running. Any instances launched after that (e.g. by sched task) notify the persistent instance to start the countdown - and if no such persistent instance exists, then there's no user logged in, so shut down immediately.

Of course, this would collapse once you have more than one persistent process - so the single-user guarantee is quite important.

Just need to figure out the IPC.

@mtitheradge
Copy link
Author

That sounds like it would work for us perfectly. I wasn't expecting you to put time into resolving the issue just for me. I'm grateful for your assistance.

BobVul added a commit that referenced this issue Nov 14, 2014
@BobVul
Copy link
Owner

BobVul commented Nov 14, 2014

You can try the persistent branch.

Launch a persistent instance on user login with IdleShutdown /p (you can do this via Task Scheduler, or the Startup folder, or the registry Run key if you want; the latter two should apply to all users more easily). There can only be one persistent instance running at any time - removing this limitation would take considerable effort.

At any time, run IdleShutdown /m <minutes>. If there's a persistent instance running, that one will be activated. If not, then it'll run by itself.

The notification icon now has an Exit context menu option. The Abort button will still exit in non-persistent mode, but in persistent mode it'll only hide - you need to use the Exit menu option to actually close it.

Note that the /m option is now necessary to specify a time. See IdleShutdown /?. This is a side effect of switching to proper options parsing.

Let me know if there are any issues - I've only done minimal testing at this time. Actually, I'd appreciate it if you could let me know if it works, too.

@mtitheradge
Copy link
Author

Thanks I will test this out on Monday and let you know the outcome.

@mtitheradge
Copy link
Author

Forgive me if I'm being silly, but do you have a download link for the persistent version?

@BobVul
Copy link
Owner

BobVul commented Nov 17, 2014

Hm. Looks like GitHub has removed the downloads section and changed it to releases since I last did something on this.

Try here: https://github.com/Elusive138/IdleShutdown/releases/tag/v2.0.0-alpha

Do note this is just for testing - I haven't really added any error handling, so the persistent instance will probably just die completely on a crash if you run into a bug. I'll see if I can improve that later, if I have some time - this little program was never really intended for anything major/serious/complex.

@mtitheradge
Copy link
Author

I've now tested this both logged on and off. When logged off the PC shuts down immediately and when logged on the user is prompted to continue or abort the shutdown.

I've created the two scheduled tasks for logon and for night time shutdown and it all works perfectly.

Thank you so much for the time and effort you've put in to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants