Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Controlling programs with time?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TokenHerbz




PostPosted: Mon Sep 11, 2006 1:33 am   Post subject: Controlling programs with time?

How would i go about makeing a program that will do the following tasks.

-Read the current time on the computer.
-Boot programs up at a specific time.
-Close programs at a specific time.
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Mon Sep 11, 2006 6:31 am   Post subject: (No subject)

Look up the Time module. You can use things like Time.Date or Time.DateSec.

You can run programs with Sys.Exec.

You cannot close running programs. That's too advanced.
NikG




PostPosted: Mon Sep 11, 2006 9:25 am   Post subject: (No subject)

The first two are simple just as Cervantes said.

If instead of closing a certain program, you want to turn off your computer (thereby closing all programs), I remember seeing some code here to do just that using Sys.Exec.
Wolf_Destiny




PostPosted: Mon Sep 11, 2006 2:12 pm   Post subject: Tada

Here ya go:

To simply shutdown:
code:
if Sys.Exec ("shutdown -s") then
%Successful!
end if

Timer: (Where 60 is a changable amount of seconds before shutdown)
code:
if Sys.Exec ("shutdown -s -t 60") then
%Successful!
end if

Timer and Comment
code:
if Sys.Exec ("shutdown -s -t 60 -c \"YOUR COMMENT HERE\"") then
%Successful!
end if



To simply restart:
code:
if Sys.Exec ("shutdown -r") then
%Successful!
end if

Timer: (Where 60 is a changable amount of seconds before reboot)
code:
if Sys.Exec ("shutdown -r -t 60") then
%Successful!
end if

Timer and Comment
code:
if Sys.Exec ("shutdown -r -t 60 -c \"YOUR COMMENT HERE\"") then
%Successful!
end if


-->And while experimenting | shutdown -a | in the command prompt will cancel a shutdown command (If on timer)

Enjoy,
~Wolf_Destiny
Wolf_Destiny




PostPosted: Mon Sep 11, 2006 2:38 pm   Post subject: (No subject)

Just Remembered this:

In WinXP there is a "taskkill" command for DOS. (I believe it's called "kill" for Win2000)

It allows you to terminate any process currently running ONE AT A TIME just like you want, right Tokenherbs? So how does it work?

First off, you need to know what's called the image name, that the program runs under. Example firefox's image name is "firefox.exe" it's simply, but neccessary. So to do this:
1. Open your program of choice (the one that Turing will close).
2. Start Menu -> Run -> Command [enter]
3. Type: "tasklist" (no quotes) and press enter.
4. Scroll around looking under the first heading (image name) until you find your program.
5. Write down the image name somewhere.
6. Then substitute the image name into this code:
code:
taskkill -F -IM <imagenamehere>

So to close firefox immediately:
code:
taskkill -F -IM firefox.exe

7. Put that line into a Sys.Exec Structure.
code:
if Sys.Exec ("taskkill -F -IM firefox.exe") then
put "This program just closed firefox, how d'ya like that?"
end if


A closer look:
-F tells the command prompt to force the program to close
-IM tells the command prompt that the image name is to follow
<imagenamehere> tells the command prompt what the heck you want to close

Hope that helps!
~Wolf_Destiny
NikG




PostPosted: Tue Sep 12, 2006 4:50 pm   Post subject: (No subject)

Wow, pretty impressive WolfDestiny.

Just to clarify two things for all future seekers of this kind of programs:

-This is being done using exisiting windows apps. So Cervantes is still correct in saying that Turing itself cannot do this.

-WoldDestiny just demonstrated the various different switches that can be used with the taskkill and shutdown apps. To find them on your own, all you have to do is open the command prompt, and type in the command followed by a "/?" (i.e. shutdown /?) to get the full list of switches available.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: