DarkBoost Posted November 30, 2018 Posted November 30, 2018 (edited) If you look at the attached image this shows 2x instances of Google Chrome I have open - a locally installed one and a Portable version which has been executed from a secondary HDD. I need to write a script to close the Portable version of Google Chrome but have no idea how to identify the correct one? Edited November 30, 2018 by DarkBoost
Loken Posted November 30, 2018 Posted November 30, 2018 $PID = Run("chrome.exe") . . . ProcessClose($PID) You can handle it by pid. "Run" command in AutoIt returns you pid of program which can you are trying to run. But if you havent pid of target program, you can try getting full path of the process. If the full path is not matching with default google chrome path you can suppose to it may be a portable program. Local $aProcessList = ProcessList() For $i = 1 To $aProcessList[0][0] $processLocation = _ProcessGetLocation($aProcessList[$i][1]) If $processLocation = "portable path of chrome" Then ProcessClose($aProcessList[$i][1]) ExitLoop EndIf Next Func _ProcessGetLocation($iPID) Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID) If $aProc[0] = 0 Then Return SetError(1, 0, '') Local $vStruct = DllStructCreate('int[1024]') DllCall('psapi.dll', 'int', 'EnumProcessModules', 'hwnd', $aProc[0], 'ptr', DllStructGetPtr($vStruct), 'int', DllStructGetSize($vStruct), 'int_ptr', 0) Local $aReturn = DllCall('psapi.dll', 'int', 'GetModuleFileNameEx', 'hwnd', $aProc[0], 'int', DllStructGetData($vStruct, 1), 'str', '', 'int', 2048) If StringLen($aReturn[3]) = 0 Then Return SetError(2, 0, '') Return $aReturn[3] EndFunc
Nine Posted November 30, 2018 Posted November 30, 2018 _WinAPI_EnumProcessModules ($pid) can do the work easily (must be run in x64 don't forget) “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
DarkBoost Posted December 4, 2018 Author Posted December 4, 2018 Thanks for this - both are very useful for what I need to achieve!
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