Start Application Timer

Discuss RoboTask here
Post Reply
Salnikov.sv
Posts: 3
Joined: Mon Apr 04, 2016 12:04 pm

Start Application Timer

Post by Salnikov.sv »

Hello. I need to organize a monitoring program performance. app launch will take place at the same time will start a timer that will run until the start of the application window. Result - txt file with the start time of the program window. After that, the program window is closed.
Run the application and closes the window, I realized. I can not count the time to realize and output to a file. Please help.
Oleg
Site Admin
Posts: 3202
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Start Application Timer

Post by Oleg »

You need two time values:
1-st value - when the program starts
2-nd value - when the program finished

see the example below:

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1416408852
Comment=STRINGLIST
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task152"
Hide=INTEGER|0
ID=INTEGER|348890740
LogOnAsUser=INTEGER|1
Name=STRING|"program monitor"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""DT1"" with value ""{dateTime}"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"1"
varname=STRING|"DT1"
varvalue=STRING|"{dateTime}"

[Actions\Action2]
ActionID=STRING|"A_GENERAL_RUN_PROG"
Enabled=INTEGER|-1
Name=STRING|"Run ""notepad """
Params=FOLDER

[Actions\Action2\Params]
ifnonzero=STRING|"0"
program=STRING|"notepad"
runas=STRING|"0"
wait=STRING|"0"

[Actions\Action3]
ActionID=STRING|"A_WAITFORPROCESS"
Enabled=INTEGER|-1
Name=STRING|"Wait for ""notepad.exe"" (Infinity)"
Params=FOLDER

[Actions\Action3\Params]
assign=STRING|"0"
infinity=STRING|"1"
more=STRING|"0"
process=STRING|"notepad.exe"
timeout=STRING|"60"

[Actions\Action4]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""DT2"" with value ""{dateTime}"""
Params=FOLDER

[Actions\Action4\Params]
expand=STRING|"1"
varname=STRING|"DT2"
varvalue=STRING|"{dateTime}"

[Actions\Action5]
ActionID=STRING|"A_SCRIPT_VBEVALUATE"
Enabled=INTEGER|-1
Name=STRING|"VB Evaluate (dt1-dt2)"
Params=FOLDER

[Actions\Action5\Params]
expression=STRING|"datesubtract(""{dt1}"", ""{dt2}"")"
line00000000=STRING|"function DateSubtract(d1, d2)"
line00000001=STRING|"'d1 and d2 are strings"
line00000002=STRING|"dt1 = cdate(d1)"
line00000003=STRING|"dt2 = cdate(d2)"
line00000005=STRING|"'convert the result back to string"
line00000006=STRING|"DateSubtract = cstr(cdate(dt1-dt2))"
line00000007=STRING|"end function"
line00000009=STRING|"'aaa = DateSubtract(""12.02.2016 10:41:00"", ""00:45:10"")"
line0000000A=STRING|"'logmessage(aaa)"
linecount=STRING|"11"
loadfromfile=STRING|"1"
variable=STRING|"dt3"

[Actions\Action6]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""date-time1  = {dt1} (Notepad starts)"""
Params=FOLDER

[Actions\Action6\Params]
icon=STRING|"1"
msg0=STRING|"date-time1  = {dt1} (Notepad starts)"
msg1=STRING|"date-time2  = {dt2} (Notepad closed)"
msg2=STRING|"-----------------------"
msg3=STRING|"result = {dt3} (working time)"
msgcount=STRING|"4"
playsound=STRING|"0"
showmessage=STRING|"1"

Oleg Yershov
Oleg
Site Admin
Posts: 3202
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Start Application Timer

Post by Oleg »

Also see more complex example.
This task monitors the NOTEPAD.exe in memory.
When you start NOTEPAD.EXE it saves beginning time into file
when you closes Notepad it calculated working time of Notepad.

This task works every 2 seconds and checks the existence of NOTEPAD in memory.
You can change the period in Cyclic trigger of this task.

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1416408852
Comment=STRINGLIST
ContinueOnError=INTEGER|0
Events=FOLDER
ExternalName=STRING|"Task154"
Hide=INTEGER|0
ID=INTEGER|355056548
LogOnAsUser=INTEGER|1
Name=STRING|"program monitor (notepad)"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|2
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action10=FOLDER
Action11=FOLDER
Action12=FOLDER
Action13=FOLDER
Action14=FOLDER
Action15=FOLDER
Action16=FOLDER
Action17=FOLDER
Action18=FOLDER
Action19=FOLDER
Action2=FOLDER
Action20=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""FILENAME"" with value ""{TempDir}\notepadmonitor.tmp"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"1"
varkind=STRING|"1"
varname=STRING|"FILENAME"
varvalue=STRING|"{TempDir}\notepadmonitor.tmp"

[Actions\Action10]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//notepad doesn't exist"
Params=FOLDER

[Actions\Action10\Params]
comment=STRING|"notepad doesn't exist"

[Actions\Action11]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action11\Params]
case=STRING|"0"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{FileExists({filename})}"

[Actions\Action12]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//calculate the difference"
Params=FOLDER

[Actions\Action12\Params]
comment=STRING|"calculate the difference"

[Actions\Action13]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""DT1"" with value ""{TextFile({filename})}"""
Params=FOLDER

[Actions\Action13\Params]
expand=STRING|"1"
varname=STRING|"DT1"
varvalue=STRING|"{TextFile({filename})}"

[Actions\Action14]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""DT2"" with value ""{DateTime}"""
Params=FOLDER

[Actions\Action14\Params]
expand=STRING|"1"
varname=STRING|"DT2"
varvalue=STRING|"{DateTime}"

[Actions\Action15]
ActionID=STRING|"A_FILE_DELETE"
Enabled=INTEGER|-1
Name=STRING|"Delete File"
Params=FOLDER

[Actions\Action15\Params]
Count=STRING|"1"
deletedirs=STRING|"0"
file0=STRING|"{FileName}"
hidden=STRING|"1"
subdir=STRING|"0"
system=STRING|"1"
ToRecycleBin=STRING|"0"

[Actions\Action16]
ActionID=STRING|"A_SCRIPT_VBEVALUATE"
Enabled=INTEGER|-1
Name=STRING|"VB Evaluate (dt1-dt2)"
Params=FOLDER

[Actions\Action16\Params]
expression=STRING|"datesubtract(""{dt1}"", ""{dt2}"")"
line00000000=STRING|"function DateSubtract(d1, d2)"
line00000001=STRING|"'d1 and d2 are strings"
line00000002=STRING|"dt1 = cdate(d1)"
line00000003=STRING|"dt2 = cdate(d2)"
line00000005=STRING|"'convert the result back to string"
line00000006=STRING|"DateSubtract = cstr(cdate(dt1-dt2))"
line00000007=STRING|"end function"
line00000009=STRING|"'aaa = DateSubtract(""12.02.2016 10:41:00"", ""00:45:10"")"
line0000000A=STRING|"'logmessage(aaa)"
linecount=STRING|"11"
loadfromfile=STRING|"1"
variable=STRING|"dt3"

[Actions\Action17]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action17\Params]
message=STRING|"notepad finished. Working time {dt3}"
type=STRING|"3"

[Actions\Action18]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""date-time1  = {dt1} (Notepad starts)"""
Params=FOLDER

[Actions\Action18\Params]
icon=STRING|"1"
msg0=STRING|"date-time1  = {dt1} (Notepad starts)"
msg1=STRING|"date-time2  = {dt2} (Notepad closed)"
msg2=STRING|"-----------------------"
msg3=STRING|"result = {dt3} (working time)"
msgcount=STRING|"4"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action19]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action2]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action2\Params]
case=STRING|"0"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{IsProcessExists(notepad.exe)}"

[Actions\Action20]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action3]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//notepad exists"
Params=FOLDER

[Actions\Action3\Params]
comment=STRING|"notepad exists"

[Actions\Action4]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action4\Params]
case=STRING|"0"
operator=STRING|"1"
type=STRING|"3"
value1=STRING|"{FileExists({filename})}"

[Actions\Action5]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//save dt1"
Params=FOLDER

[Actions\Action5\Params]
comment=STRING|"save dt1"

[Actions\Action6]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action6\Params]
message=STRING|"Save dt1 = {DateTime}"
type=STRING|"3"

[Actions\Action7]
ActionID=STRING|"A_FILE_TEXTWRITE"
Enabled=INTEGER|-1
Name=STRING|"Create text file {filename}"
Params=FOLDER

[Actions\Action7\Params]
encode=STRING|"0"
fileexists=STRING|"0"
filname=STRING|"{filename}"
line0=STRING|"{dateTime}"
linecount=STRING|"1"
suppress=STRING|"1"

[Actions\Action8]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action9]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else"

[Events]
Event1=FOLDER

[Events\Event1]
Enabled=INTEGER|-1
EventID=STRING|"E_GENERAL_CYCLIC"
Params=FOLDER
UnigueID=INTEGER|16445185

[Events\Event1\Params]
interval=STRING|"2"
notsatrtatactivation=STRING|"0"


Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
Do not forget to enable the task after importing.
Oleg Yershov
Post Reply