maklin Posted November 11, 2018 Posted November 11, 2018 Hello there, I cant delete file in action1, if process exists. This is probably because the same file is used in action2. If i Try only Action1, with start test.exe manually, its ok. ( without action2) Can someone help me pls? expandcollapse popupLocal $Timer1, $Delay1 = 55000 Local $Timer2, $Delay2 = 10000 While 1 If $Timer1 = '' Or TimerDiff($Timer1) > $Delay1 Then $Timer1 = TimerInit() Action1() EndIf If $Timer2 = '' Or TimerDiff($Timer2) > $Delay2 Then $Timer2 = TimerInit() Action2() EndIf ; Briefly pause to avoid excessive CPU usage Sleep(100) WEnd Func Action1() If ProcessExists("test.exe") Then ; Check if the process is running. ProcessClose("test.exe") ; - this is ok FileDelete("C:\ProgramData\test\test.exe") ; - here is my problem Else EndIf EndFunc Func Action2() $idleTimer = _Timer_GetIdleTime() If $idleTimer > 8000 And Not ProcessExists("test.exe") Then Run("C:\ProgramData\test\test.exe ElseIf $idleTimer < 500 Then ProcessClose("test.exe") EndIf EndFunc
Nine Posted November 12, 2018 Posted November 12, 2018 god, i dont understand one bit what you are trying to do, most of the code is full of bugs “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Trong Posted November 12, 2018 Posted November 12, 2018 Like this? expandcollapse popup#include <Timers.au3> Global $Timer1, $Delay1 = 55000 Global $Timer2, $Delay2 = 10000 Global Const $AppName = "test.exe" Global Const $AppPath = "C:\ProgramData\test\" & $AppName Global $CurrenAction = 0 ; Current Task Run While 1 If $Timer1 = '' Or TimerDiff($Timer1) > $Delay1 Then $Timer1 = TimerInit() Action1() EndIf If $Timer2 = '' Or TimerDiff($Timer2) > $Delay2 Then $Timer2 = TimerInit() Action2() EndIf ; Briefly pause to avoid excessive CPU usage Sleep(100) WEnd Func Action1() If $CurrenAction <> 0 Then Return $CurrenAction = 1 ; START If ProcessExists($AppName) Then ; Check if the process is running. ProcessClose($AppName) ; - this is ok FileDelete($AppPath) ; - here is my problem Else EndIf $CurrenAction = 0 ; DONE EndFunc ;==>Action1 Func Action2() If $CurrenAction <> 0 Then Return $CurrenAction = 2 ; START $idleTimer = _Timer_GetIdleTime() If $idleTimer > 8000 And Not ProcessExists($AppName) Then Run($AppPath) ElseIf $idleTimer < 500 Then ProcessClose($AppName) EndIf $CurrenAction = 0 ; DONE EndFunc ;==>Action2 Regards,
maklin Posted November 12, 2018 Author Posted November 12, 2018 Hi VIP,thank you very much, but its the same.I try add other file to delete, and this one was deleted.. expandcollapse popup#include <Timers.au3> Global $Timer1, $Delay1 = 55000 Global $Timer2, $Delay2 = 10000 Global Const $AppName = "test.exe" Global Const $AppPath = "C:\ProgramData\test\" & $AppName Global $CurrenAction = 0 ; Current Task Run While 1 If $Timer1 = '' Or TimerDiff($Timer1) > $Delay1 Then $Timer1 = TimerInit() Action1() EndIf If $Timer2 = '' Or TimerDiff($Timer2) > $Delay2 Then $Timer2 = TimerInit() Action2() EndIf ; Briefly pause to avoid excessive CPU usage Sleep(100) WEnd Func Action1() If $CurrenAction <> 0 Then Return $CurrenAction = 1 ; START If ProcessExists($AppName) Then ; Check if the process is running. ProcessClose($AppName) ; - this is ok FileDelete(C:\ProgramData\test\testfile.txt) ; - this one was deleted FileDelete($AppPath) ; - here is my problem Else EndIf $CurrenAction = 0 ; DONE EndFunc ;==>Action1 Func Action2() If $CurrenAction <> 0 Then Return $CurrenAction = 2 ; START $idleTimer = _Timer_GetIdleTime() If $idleTimer > 8000 And Not ProcessExists($AppName) Then Run($AppPath) ElseIf $idleTimer < 500 Then ProcessClose($AppName) EndIf $CurrenAction = 0 ; DONE EndFunc ;==>Action2
caramen Posted November 12, 2018 Posted November 12, 2018 @maklin If the process is in use. Maybe your computer is too slow. Try to add a wait in your function Action1 () Func Action1() If $CurrenAction <> 0 Then Return $CurrenAction = 1 ; START If ProcessExists($AppName) Then ; Check if the process is running. ProcessClose($AppName) ; - this is ok Sleep (5000) ; you reduce the time after the first try if it work. FileDelete($AppPath) ; - here is my problem Else EndIf $CurrenAction = 0 ; DONE EndFunc ;==>Action1 My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki
maklin Posted November 12, 2018 Author Posted November 12, 2018 @caramen, @VIP THX a lot, now its working good.I will test it more, but i think its OK.
caramen Posted November 12, 2018 Posted November 12, 2018 12 minutes ago, maklin said: @caramen, @VIP THX a lot, now its working good.I will test it more, but i think its OK. You got sometime further actions when you close an application. Temp cleanning, services closing... what ever... It can long sometime more than a minute... My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now