Windows 7 Forums


Reply
Thread Tools

Task scheduler conditions

 
 
-Sandro- -Sandro- is offline
New Member
Join Date: Sep 2009
Posts: 17
Thanked: 0
 
      01-17-2010
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.
 
Reply With Quote
 
 
 
 
Ian Ian is offline
Administrator
Ian's Avatar
Join Date: Oct 2008
Location: England
Posts: 3,091
Thanked: 450
Ian's Twitter Pag
 
      01-18-2010
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!
 
Reply With Quote
 
-Sandro- -Sandro- is offline
New Member
Join Date: Sep 2009
Posts: 17
Thanked: 0
 
      01-18-2010
Are you sure this is for me? I can't understand where it could help me in what I wanna do.
 
Reply With Quote
 
Ian Ian is offline
Administrator
Ian's Avatar
Join Date: Oct 2008
Location: England
Posts: 3,091
Thanked: 450
Ian's Twitter Pag
 
      01-18-2010
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.

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?
 
Reply With Quote
 
-Sandro- -Sandro- is offline
New Member
Join Date: Sep 2009
Posts: 17
Thanked: 0
 
      01-18-2010
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
 
Reply With Quote
 
-Sandro- -Sandro- is offline
New Member
Join Date: Sep 2009
Posts: 17
Thanked: 0
 
      01-25-2010
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?
 
Reply With Quote
 
Ian Ian is offline
Administrator
Ian's Avatar
Join Date: Oct 2008
Location: England
Posts: 3,091
Thanked: 450
Ian's Twitter Pag
 
      01-25-2010
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nothing but the mouse and a few task bar popup windows work after resuming from sleep wmassey Windows 7 Support 8 06-20-2010 03:03 AM
Task Scheduler unable to create file CRGibson Windows 7 Support 1 01-24-2010 04:07 AM
Disappearing Web Video Task Bars. raffles General Discussion 0 01-09-2010 08:47 PM
Task Manager question. sethm1 Installation, Setup and Updates 4 10-30-2009 12:15 AM
Task Scheduler doesnt work? sombster Windows 7 Support 0 05-05-2009 10:49 PM


All times are GMT +1. The time now is 10:23 PM.
W7Forums is an independent website and is not affiliated with Microsoft Corporation.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33