redvern Posted August 7, 2023 Share Posted August 7, 2023 Hello, I have posted this to an old topic but got no response, so I thought maybe I should start a new one. I have been working on it solve the problem my company has with an ERP software. There are limited number of licenses and people just leave the software open logged in which prevents others to use it. So, I've wanted to automatically close the software on user PCs after a certain period of being idle. The problem I have; the ERP software obviously predicted people would try this so they have a way of not logging the user off when the software is closed from task manager. Or using ProcessClose/WinKill commands. The only way to close the software and successfully log out is by pressing the "X" on the window and then clicking "Yes" in the pop-up window. Pressing "e" should also work. ChatGPT suggested using WinClose with exact window name. I can go as far as the little pop-up window but then things go haywire. Either it can't click "Yes" and the pop-up window stuck or somehow all the menus disappear on the window and I have to use the task manager to close the software. I'm attaching the code I have used. I'm also open to other ideas and maybe there is a different command which would force close the software meanwhile logging it off. Thanks in advance. expandcollapse popup#include <Timers.au3> #include <WinAPI.au3> Global Const $IDLE_MINUTES = 1 Global Const $sWindowTitle = "ERP Software" Global $hProcessWnd, $aProcessList, $sWindowClass Global $iTimerInit = TimerInit() Global $iIdleTime = _Timer_GetIdleTime() ; Disable Pause hotkey (Ctrl+Pause) to prevent users from pausing the script HotKeySet("^{Pause}", "NoPause") ; Hide the tray icon #NoTrayIcon Func NoPause() ; Do nothing EndFunc While 1 $hProcessWnd = WinGetHandle($sWindowTitle) If $hProcessWnd <> 0 Then $iIdleTime = _Timer_GetIdleTime() $sWindowClass = WinGetClassList($hProcessWnd) If WinActive($hProcessWnd) Then $iTimerInit = TimerInit() If TimerDiff($iTimerInit) >= $IDLE_MINUTES * 60 * 1000 Or $iIdleTime >= $IDLE_MINUTES * 60 * 1000 Then ; Forcefully close the main window WinKill($hProcessWnd) ; Wait for the small window to appear (adjust the sleep time if needed) Sleep(1000) ; Send "Enter" key to the small window to select the default option ("Yes") Send("{ENTER}") EndIf EndIf Sleep(100) WEnd Link to comment Share on other sites More sharing options...
Nine Posted August 7, 2023 Share Posted August 7, 2023 Have you tried this : Local $iRet = RunWait ("TaskKill /IM " & $sNameExe & " /F", "", @SW_HIDE) “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...
redvern Posted August 7, 2023 Author Share Posted August 7, 2023 1 hour ago, Nine said: Have you tried this : Local $iRet = RunWait ("TaskKill /IM " & $sNameExe & " /F", "", @SW_HIDE) Hey, Thanks for the reply. I've tried this just now. It successfully closes the process like ProcessClose but the user is still logged in to the server. Link to comment Share on other sites More sharing options...
Nine Posted August 7, 2023 Share Posted August 7, 2023 In my sense, it means there is another process still going. “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...
redvern Posted August 7, 2023 Author Share Posted August 7, 2023 5 minutes ago, Nine said: In my sense, it means there is another process still going. I've thought about that too but there is no other process as far as I can notice. How can I be sure? Link to comment Share on other sites More sharing options...
Developers Jos Posted August 7, 2023 Developers Share Posted August 7, 2023 (edited) So you probably require a real logoff to be performed by the software. Can't you simulate that? For starters I would try WinClose() as that should simulate the clicking the X. ( Assuming that is what normally is required for the license to be released?) Edited August 7, 2023 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
redvern Posted August 8, 2023 Author Share Posted August 8, 2023 (edited) 15 hours ago, Jos said: So you probably require a real logoff to be performed by the software. Can't you simulate that? For starters I would try WinClose() as that should simulate the clicking the X. ( Assuming that is what normally is required for the license to be released?) I've tried that too and I'm attaching the code. But for some reason it fails to press "yes" successfully in the pop-up window after clicking "X" on the main window. Btw, the pop-up window asks "are you certain you want to close the software?" and there are three options for clicking: yes, no and cancel. expandcollapse popup#include <Timers.au3> #include <WinAPI.au3> Global Const $IDLE_MINUTES = 1 Global Const $sWindowTitle = "ERP Software" Global $hProcessWnd, $aProcessList, $sWindowClass Global $iTimerInit = TimerInit() Global $iIdleTime = _Timer_GetIdleTime() ; Disable Pause hotkey (Ctrl+Pause) to prevent users from pausing the script HotKeySet("^{Pause}", "NoPause") ; Hide the tray icon #NoTrayIcon Func NoPause() ; Do nothing EndFunc While 1 $hProcessWnd = WinGetHandle($sWindowTitle) If $hProcessWnd <> 0 Then $iIdleTime = _Timer_GetIdleTime() $sWindowClass = WinGetClassList($hProcessWnd) If WinActive($hProcessWnd) Then $iTimerInit = TimerInit() If TimerDiff($iTimerInit) >= $IDLE_MINUTES * 60 * 1000 Or $iIdleTime >= $IDLE_MINUTES * 60 * 1000 Then ; Close the main window gracefully WinClose($hProcessWnd) ; Wait for the small window to appear (adjust the sleep time if needed) Sleep(1000) ; Send "Enter" key to the small window to select the default option ("Yes") Send("{ENTER}") EndIf EndIf Sleep(100) WEnd Edited August 8, 2023 by redvern Link to comment Share on other sites More sharing options...
Developers Jos Posted August 8, 2023 Developers Share Posted August 8, 2023 Are you sure the Yes button has the Focus when you Send("{Enter}")? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
redvern Posted August 8, 2023 Author Share Posted August 8, 2023 1 hour ago, Jos said: Are you sure the Yes button has the Focus when you Send("{Enter}")? short answer, I don't know. normally when I manually click "X" then I can press "enter" or "e" with hand to close the software. the focus is on the "yes" button. but I don't know what exactly happens when the script is running. It looks like either it can't press any button or for some reason it breaks the UI and the menus dissapper one by one. 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