burntfoot Posted June 16, 2019 Share 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 Link to comment Share on other sites More sharing options...
argumentum Posted June 16, 2019 Share Posted June 16, 2019 nothing, conceptually speaking. Code wise, you're gonna close ProcessClose("every.exe") constantly. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
burntfoot Posted June 16, 2019 Author Share Posted June 16, 2019 @argumentum If it's closing constantly, how would you revise it? Link to comment Share on other sites More sharing options...
Nine Posted June 16, 2019 Share 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... “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) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
argumentum Posted June 16, 2019 Share 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 my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
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