AutoHotkey Community

It is currently May 26th, 2012, 3:47 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: April 1st, 2009, 10:55 am 
Offline

Joined: April 13th, 2007, 8:28 am
Posts: 28
hi,

i would like my app is launch every days at 5:00 pm, i have read some thread in this forum but i have found some idea:

1- create windows' planified task manualy
2- create a loop and check day and hour (too memory used)
3- process (i haven't understand how to use it and without other app)

so only the first idea interest me but i want to create it with ahk code.

someone to help me or have another idea?


Last edited by enigmatiqk on April 7th, 2009, 8:39 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 1st, 2009, 12:21 pm 
Offline

Joined: June 9th, 2008, 2:32 am
Posts: 936
Location: Canada
Code:
Loop,
{
Sleep, 60000; check time every minet
if %A_Hour% = 17 ; 5 o clock french time
{
; your script here
}
}


Put this in start up folder.

I dont under stand what you mean by "Planified"

_________________
Image
I know i have 6 legs. It's cuz I'm special.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 1st, 2009, 1:11 pm 
Offline

Joined: April 13th, 2007, 8:28 am
Posts: 28
SpiderGames wrote:
Code:
Loop,
{
Sleep, 60000; check time every minet
if %A_Hour% = 17 ; 5 o clock french time
{
; your script here
}
}


Put this in start up folder.


this code will be not use too many memory or proc?

SpiderGames wrote:
I dont under stand what you mean by "Planified"


windows:
start menu> programs > accesoires (in french) > system tools (french trad)>scheduled task

it's the windows assistant with u can schedule any execution in the time

sorry for my poor english :?


[EDIT] to add a scheduled task, i must use windows cmd "AT"

problem:
- only admin command
- when my app is already open, windows open it again...


so i have turn my choice to your loop

but i want to activate and desactivate this loop with the same button, and i don't know how i can do that...

Code:
planifier:
   Suspend , Permit
   Menu, tray, ToggleCheck, Planifier la saisie

   ;lecture du fichier ini
   IniRead, h, SAFA.ini, PLANIFICATION, HOUR, %A_ScriptDir%
   IniRead, m, SAFA.ini, PLANIFICATION, Min, %A_ScriptDir%
   
   ifEqual,Planified,1
   {
      Planified=0
   }else{
      Planified = 1
      Loop
      {
         ; check time every min
         Sleep, 60000
         ;verifie qu'on est bien dans la semaine du lundi(2) au vendredi(6)
         IfInString,23456,%A_WDay%
         {
            ifEqual,h,%A_Hour%
            {
               IfEqual, m, %A_Min%
               {
                  ifEqual,Opened,0
                  {
                     msgbox, ouverture
                     goSub, init
                     GoSub, load
                     Sleep, 60000
                  }else{
                     Sleep, 60000
                  }
               }
            }
         }
         ifEqual,Planified,0
            Break
      }
   }
return

problem, my memory increase with time

[/EDIT]


Last edited by enigmatiqk on April 1st, 2009, 4:56 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 1st, 2009, 4:47 pm 
Offline

Joined: October 15th, 2007, 7:23 pm
Posts: 252
A command line version of the Task Scheduler is available for use in Windows XP and later systems. It is called schtask.exe. You might could use the AHK Run command with the appropriate command line switches to schedule a task from an AHK script.

Info on using schtask.exe is here:

http://msdn.microsoft.com/en-us/library/bb736357(VS.85).aspx

EDIT: You can also show tasks, delete tasks, run tasks immediately.

dmatch

[ Moderator!: MSDN Link fixed ]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 1st, 2009, 8:19 pm 
Offline

Joined: October 15th, 2007, 7:23 pm
Posts: 252
The Command Line version of Task Scheduler requires 2 backslashes in front of the System/Computer name (\\Computername). You can use AHK's A_ComputerName and add the backslashes. On my XP it also requires that you give System Name, Username, and Password if any one of them is specified. You can get a Username using AHK's A_Username. I also had to give a Run as Username and Run as Password to get it to work when specifying the Username.

This works on my XP system and creates a task called Testing (runs calc.exe after 5 minutes). It will then delete that task.
Code:
SetTitleMatchMode, 2
TaskName=Testing

;Do not necessarily need the following
Computername=\\%A_ComputerName%
Username=%A_Username%
RunAsUsername=%A_Username%
Password=
RunAsPassword=
;Do not necessarily need the above

;Create a Run time and date for schedule for demonstration
RunTime:=A_Now
RunTime+=5, minutes
Time:=SubStr(RunTime, 9, 2) . ":" . SubStr(RunTime, 11, 2) . ":" . SubStr(RunTime, 13, 2)
Date:=SubStr(RunTime, 5, 2) . "/" . SubStr(RunTime, 7, 2) . "/" . SubStr(RunTime, 1, 4)

;Run the simplest form of schtasks.exe
RunWait, %A_WinDir%\System32\schtasks.exe /Create /SC ONCE /TN %TaskName% /TR C:\Windows\system32\calc.exe /ST %Time% /SD %Date%
;The Run below is a more complex version that could be implemented
;If you enter usernames and passwords at top of file
;you will not be prompted for password input.
;RunWait, %A_WinDir%\System32\schtasks.exe /Create /S %Computername% /U %Username% /P %password% /RU %RunAsUsername% /RP %RunAsPassword% /SC ONCE /TN %TaskName% /TR C:\Windows\system32\calc.exe /ST %Time% /SD %Date%

;Just something to let you know what's going on
MsgBox, The task, %Taskname%, should have been created in Task Scheduler.`nIt will run in about 5 minutes.
MsgBox, Will now delete %Taskname% from Task Scheduler in case it is still there.

;Delete the task
Run, %A_WinDir%\System32\schtasks.exe /Delete /TN %TaskName%
;The Run below is a more complex version that could be implemented
;If you enter usernames and passwords at top of file
;you will not be prompted for password input.
;Run, %A_WinDir%\System32\schtasks.exe /Delete /S %Computername% /U %Username% /TN %TaskName%

;Switch to schtasks window
WinWaitActive, schtasks
Send, y ;Answer "want to delete prompt".
ExitApp



EDIT: I think you may be using Vista. If you are using Vista I don't know if schtasks.exe is in it. It is in the Windows\System32 folder on Windows XP.

dmatch


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 2nd, 2009, 8:48 am 
Offline

Joined: April 13th, 2007, 8:28 am
Posts: 28
schtask is not found on my os (winxp pro), but the command "AT" looks like schtask command.

i will create a test in first cod line to check if app is already launch, i this case, i will just show it.

but we need to be admin ...

thank you for your help, i will use it now

but i would like someone can answer me about the loop and the increased used memory, just to sleep more intelligent tonight :P


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 6th, 2009, 4:23 pm 
Offline

Joined: April 13th, 2007, 8:28 am
Posts: 28
ok about schtaskS

but it can't recognize my file because the path have space and is not arounded by ", and folder app is not set (just 'c:\')
if a use ", they be ignored

if someone can help me about that please :)

[EDIT]
about space, use \" ...\"
ex: "\"c:\program files\...""
[/EDIT]

ps: i search someone who can explain me how i can optimiz loop/memory


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Exabot [Bot], notsoobvious and 21 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group