burntfoot 0 Posted June 16, 2019 I have a script that should execute upon user going idle. Once idle, I wanted a command window to open and pass the command to run a batch file. The batch file executes commands both in the command window and a powershell script in a powershell window. I have both of their paths set as environment variables in paths. The script runs fine on idle, but when moving my mouse upon wakeup, the command and powershell don't close. Could someone let me know what I'm doing wrong? My script below: #include <Timers.au3> While 1 Sleep(10) $idleTimer = _Timer_GetIdleTime() If $idleTimer > 60000 And Not ProcessExists("cmd.exe") And Not ProcessExists("pwsh.exe") Then Run(@ComSpec & " /c " & "C:\Users\...\Desktop\mybatchfile.bat") ElseIf $idleTimer < 10 Then ProcessClose("cmd.exe") ProcessClose("pwsh.exe") EndIf WEnd Share this post Link to post Share on other sites
argumentum 566 Posted June 16, 2019 nothing, conceptually speaking. Code wise, you're gonna close ProcessClose("every.exe") constantly. Follow the link to see my signature's stuff. Share this post Link to post Share on other sites
burntfoot 0 Posted June 16, 2019 @argumentum If it's closing constantly, how would you revise it? Share this post Link to post Share on other sites
Nine 993 Posted June 16, 2019 Here one way I would do it : #include <Timers.au3> Opt("MustDeclareVars", 1) Local $idleTimer, $bIdle = False HotKeySet("{ESC}", "_Exit") While 1 Sleep(10) $idleTimer = _Timer_GetIdleTime() If $idleTimer > 10000 Then ; maybe it should be a Or there instead of a And ? If Not ProcessExists("cmd.exe") And Not ProcessExists("pwsh.exe") Then Run(@ComSpec & " /c C:\Users\...\Desktop\mybatchfile.bat") $bIdle = True ElseIf $bIdle Then If ProcessExists("cmd.exe") Then ProcessClose("cmd.exe") If ProcessExists("pwsh.exe") Then ProcessClose("pwsh.exe") $bIdle = False EndIf WEnd Func _Exit() Exit EndFunc ;==>_Exit This way you could create manually a cmd.exe console (for example) while not idle, but you would need to manually close it before going idle. If this is not what you want, you will have to adjust the script accordingly... Not much of a signature but working on it... Spoiler Block all input without UAC Save/Retrieve Images to/from Text Tool to search content in au3 files Date Range Picker Sudoku Game 2020 Overlapped Named Pipe IPC x64 Bitwise Operations Multi-keyboards HotKeySet Fast and simple WCD IPC GIF Animation (cached) Share this post Link to post Share on other sites
argumentum 566 Posted June 16, 2019 (edited) #include <Timers.au3> $Running = 0 While 1 Sleep(10) $idleTimer = _Timer_GetIdleTime() If $idleTimer > 60000 Then If Not $Running Then $Running = Run(@ComSpec & " /c " & "C:\Users\...\Desktop\mybatchfile.bat") Else If $Running Then ProcessClose("pwsh.exe") ; tho, if you close this ProcessClose("cmd.exe") ; this should close itself $Running = 0 EndIf EndIf WEnd PS: @Nine answered at the same time Edited June 16, 2019 by argumentum =) Follow the link to see my signature's stuff. Share this post Link to post Share on other sites