Task scheduler conditions

Joined
Sep 24, 2009
Messages
17
Reaction score
0
Hello
do you know what condition could I use in batch to run something only if the PC has been ON for longer than X minutes?

I'll explain, I have 2 tasks (useful only when I'm not home and I dont want the PC to be always on) than runs every 12h. The first wakes the PC up and gets some data from an external device and the second puts it back to hibernation after 10 minutes. What I want to do is control the second one, the "put it back to hibernation" task and prevent the execution only if the PC has been on for more than 10 minutes, which means I'm home and using it, so it will prevent the PC to hibernate while I'm using it.
 

Ian

Administrator
Joined
Oct 17, 2008
Messages
3,484
Reaction score
632
I love batch files ;) I've spent the last few days writing a backup script using lots of command line utilities for MySQL, FTP etc...

What you could do is run a task as soon as your PC boots up and just use something like sleep.exe to pause the batch process for 600 seconds (10 mins) before processing the rest of the file.

You can download sleep.exe from this page (or direct from MS in a resource kit) :http://www.computerhope.com/dutil.htm

I hope that's some help!
 
Joined
Sep 24, 2009
Messages
17
Reaction score
0
Are you sure this is for me? I can't understand where it could help me in what I wanna do.
 

Ian

Administrator
Joined
Oct 17, 2008
Messages
3,484
Reaction score
632
Sorry, I misread what you were asking for - I thought you wanted to wait 10 mins before launching the process. I re-read it and now I see you want to cancel the task if your PC is active after 10 mins. :eek:

Can you explain how you are currently launching the task? Is the first task a .bat file that you launch on boot? Also, what are you using the hibernate the PC after 10 mins?
 
Joined
Sep 24, 2009
Messages
17
Reaction score
0
I put the PC in hibernation manually when I go to sleep/go out of the city.

at 6 am and 6 pm one task runs which is:

"C:\Program Files (x86)\Cumulus\cumulus.exe"

a simple task created by task scheduler that wakes up the PC from hibernation

Then after 10 minutes (6.10 am and 6.10 pm) the other task runs with these two lines

taskkill /IM cumulus.exe
"C:\Windows\System32\shutdown.exe" /h

what I wanna do is not run the second task if the pc has been on for more than 10 minutes which means I've been using it and the first task didn't obviously wake up from hibernation
 
Joined
Sep 24, 2009
Messages
17
Reaction score
0
I was thinking I could create a task that writes a file with the current timestamp every time I startup Windows, so if the hibernation task finds that the date is older than 10 minutes ago it won't start :)
is this possibile to do?
 

Ian

Administrator
Joined
Oct 17, 2008
Messages
3,484
Reaction score
632
Sorry for not replying before, I missed this post.

Yes, that would be a possible way to do it - perhaps using Powershell which is an improved scripting environment.

I have tried to find an easy way to come up with an uptime script in Windows 7, but I can't figure it out. In XP it would have been easier to have a script that would compare uptime and perform a set of conditionals.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top