Link to home
Create AccountLog in
Avatar of hypercube
hypercubeFlag for United States of America

asked on

schtasks to run in .bat file - questions on "Start the task only if the computer is idle for"

As I've already done recently, I'm again setting up a GPO to run a startup script to generate a task in Task Scheduler.  
Everything seems to be working fine except the command line command for making the Scheduled Task.
Here it is:
schtasks /create /TN "idle logoff" /RU "NT AUTHORITY\SYSTEM" /IT /RL HIGHEST /SC ONIDLE /I 120 /TR C:\Users\Public\Scripts\logoff.bat

Open in new window

User generated imageNow, the /I should set the check box for Start the task only if the computer is idle for: and add 120 minutes in the pulldown box, right?
But, it doesn't.
Also, I'd like to set the Wait for idle for: 16 minutes but there appears to be no opportunity using the schtasks command at all.  Well, I can do without that....

Any insights?
Avatar of McKnife
McKnife
Flag of Germany image

I have no idea why you would use a script to create the task, in the first place.
Tasks may be pre-configured using group policy preference task items - please try that.
Avatar of hypercube

ASKER

McKnife:  Good question!
I tried that before and was stopped by a recent Windows update.
https://www.experts-exchange.com/questions/29176454/GPO-to-schedule-Windows-restarts.html
https://www.experts-exchange.com/questions/29177792/GPO-deployed-but-startup-script-from-GPO-not-running-Need-to-debug.html
I was tempted to revisit but this one is almost exactly the same in that regard.
In the first case I needed to reboot the computers at 9 p.m.
In this case I need to log off the user account upon 120 minutes of idle.
The scripts are nearly identical:
shutdown -r
shutdown -l
The difference is in the scheduled task setup.
In looking, while the local Task Scheduler allows one to enter any times in Conditions, the GPO Task Scheduler interface only allows values from its  pulldown selector.  Not suitable in this case.

I wasn't pressed to pursue all the solutions the first time.  Maybe now.
Also, it makes me wonder here if PowerShell might not have a command that's better than "schtasks"?
ASKER CERTIFIED SOLUTION
Avatar of McKnife
McKnife
Flag of Germany image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Please note that I edited my code by adding the parameter /f in order to overwrite (possibly already present) tasks of the same name!
What a great idea!  Thanks!  I've got one in testing now.