Jump to content

Recommended Posts

Posted (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?

chrome.jpg

Edited by DarkBoost
Posted
$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

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...