Sign in to follow this  
Followers 0
Cuervo

Can you get a File Version from Process

12 posts in this topic

Hello all,

Is there away to get the file version number from a running process?

$proc = ProcessExists(GUICtrlRead($combo))

$ver = FileGetVersion($Proc)

Thanks for any help.


-Tim

Share this post


Link to post
Share on other sites



Determine the name of the executable file associated with the process and use FileGetVersion() on that.

There are examples posted.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Determine the name of the executable file associated with the process and use FileGetVersion() on that.

There are examples posted.

Then that should have been my search, how to determine the name of an executable file associated with the process.

I'll try that, thanks.

Edited by Cuervo

-Tim

Share this post


Link to post
Share on other sites

I'm on page 8 of my search and with no viable examples, doesn't any have something bookmarked they could link me to?


-Tim

Share this post


Link to post
Share on other sites

I'm on page 8 of my search and with no viable examples, doesn't any have something bookmarked they could link me to?

Try process get filename or WTSEnumerateProcesses or (my favorite) _ProcessList

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Try process get filename or WTSEnumerateProcesses or (my favorite) _ProcessList

I know the name of the process, I just need to find the path of the process.

I'm going to try with this UDF

;===============================================================================
;
; Function Name:           _ProcessListEx()
;
; Function Description:    Gets Process List with extended info, plus can retrieve only a processes with specific resources strings.
;
; Parameter(s):            $sResourceName [Optional] - Resource name of the process filename, i.e. "CompiledScript".
;                          $sInResString [Optional] - String to check in the resource name.
;                          $iWholeWord [Optional] - Defines if the $sInResString will be compared as whole string (default is 1).
;
; Requirement(s):          None.
;
; Return Value(s):         On Success -  Return 2-dimentional array, where:
;                                                                   $aRet_List[0][0] = Total processes (array elements).
;                                                                   $aRet_List[N][0] = Process Name.
;                                                                   $aRet_List[N][1] = PID (Process ID).
;                                                                   $aRet_List[N][2] = Process File Path.
;                          On Failure -  Return '' (empty string) and set @error to:
;                                                                   1 - Unable to Open Kernel32.dll.
;                                                                   2 - Unable to Open Psapi.dll.
;                                                                   3 - No Processes Found.
;
; Author(s):               G.Sandler (a.k.a MrCreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru)
;
;=====================================================================

-Tim

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I guess I'm not being to clear here.

I know the name of the process and when I do a FileGetVersion on the process I just zeros. So, I'm thinking I need to pass the patch to the of the process to check it correctly.

Am I making this harder then it needs to be?

This doesn't work. It just returns zeros.

$PID = ProcessExists("Program.exe")
$ver = FileGetVersion($PID)

MsgBox (0,'',$ver)
Edited by Cuervo

-Tim

Share this post


Link to post
Share on other sites

$PID = ProcessExists("Program.exe")
msgbox(0,"",$PID)
$ver = FileGetVersion($PID)

MsgBox (0,'',$ver)

Share this post


Link to post
Share on other sites

This should do what you need. Change $yourExe

#include <Array.au3>

$aProcListEx = _ProcessListEx()
$yourExe = "jqs.exe"

If @error Then
    MsgBox(48, "_ProcessListEx - Error", StringFormat("There was an error to get ProcessList (@error = %i)", @error))
Else
 For $i = 1 to $aProcListEx[0][0]
 If $aProcListEx[$i][0] = $yourExe Then
     $Version = FileGetVersion($aProcListEx[$i][2],"FileVersion")
     MsgBox(0,"","Path to '" & $YourExe & "' is '" & $aProcListEx[$i][2] & "'" & @CRLF & "File Version is: " & $Version)
 EndIf
 Next
EndIf

;===============================================================================
;
; Function Name:    _ProcessListEx()
;
; Function Description: Gets Process List with extended info, plus can retrieve only a processes with specific resources strings.
;
; Parameter(s):     $sResourceName [Optional] - Resource name of the process filename, i.e. "CompiledScript".
;   $sInResString [Optional] - String to check in the resource name.
;   $iWholeWord [Optional] - Defines if the $sInResString will be compared as whole string (default is 1).
;
; Requirement(s):   None.
;
; Return Value(s):  On Success - Return 2-dimentional array, where:
;   $aRet_List[0][0] = Total processes (array elements).
;   $aRet_List[N][0] = Process Name.
;   $aRet_List[N][1] = PID (Process ID).
;   $aRet_List[N][2] = Process File Path.
;   On Failure - Return '' (empty string) and set @error to:
;   1 - Unable to Open Kernel32.dll.
;   2 - Unable to Open Psapi.dll.
;   3 - No Processes Found.
;
; Author(s):    G.Sandler (a.k.a MrCreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru)
;
;=====================================================================
Func _ProcessListEx($sResourceName="", $sInResString="", $iWholeWord=1)
    Local $aProcList = ProcessList()
    Local $hKernel32_Dll = DllOpen('Kernel32.dll'), $hPsapi_Dll = DllOpen('Psapi.dll')
    Local $aOpenProc, $aProcPath, $sFileVersion, $aRet_List[1][1]

    If $hKernel32_Dll = -1 Then Return SetError(1, 0, '')

    If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@SystemDir & '\Psapi.dll')
    If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@WindowsDir & '\Psapi.dll')
    If $hPsapi_Dll = -1 Then Return SetError(2, 0, '')

    Local $vStruct  = DllStructCreate('int[1024]')
    Local $pStructPtr = DllStructGetPtr($vStruct)
    Local $iStructSize = DllStructGetSize($vStruct)

    For $i = 1 To UBound($aProcList)-1
    $aOpenProc = DllCall($hKernel32_Dll, 'hwnd', 'OpenProcess', _
    'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $aProcList[$i][1])

    If Not IsArray($aOpenProc) Or Not $aOpenProc[0] Then ContinueLoop

    DllCall($hPsapi_Dll, 'int', 'EnumProcessModules', _
    'hwnd', $aOpenProc[0], _
    'ptr', $pStructPtr, _
    'int', $iStructSize, _
    'int_ptr', 0)

    $aProcPath = DllCall($hPsapi_Dll, 'int', 'GetModuleFileNameEx', _
    'hwnd', $aOpenProc[0], _
    'int', DllStructGetData($vStruct, 1), _
    'str', '', _
    'int', 2048)

    If Not IsArray($aProcPath) Or StringLen($aProcPath[3]) = 0 Then ContinueLoop

    $sFileVersion = FileGetVersion($aProcPath[3], $sResourceName)

    If $sResourceName = "" Or $sFileVersion = $sInResString Or _
    ($iWholeWord = 0 And StringInStr($sFileVersion, $sInResString)) Then

    $aRet_List[0][0] += 1
    ReDim $aRet_List[$aRet_List[0][0]+1][3]
    $aRet_List[$aRet_List[0][0]][0] = $aProcList[$i][0]     ;Process Name
    $aRet_List[$aRet_List[0][0]][1] = $aProcList[$i][1]     ;PID (Process ID)
    $aRet_List[$aRet_List[0][0]][2] = $aProcPath[3]     ;Process File Path
    EndIf
    Next

    DllClose($hKernel32_Dll)
    DllClose($hPsapi_Dll)

    If $aRet_List[0][0] < 1 Then Return SetError(3, 0, '')
    Return $aRet_List
EndFunc


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thank you very much Water.

I have one question about your script.

If I include the entire ProcessEx.au3 script in my script it works fine, but if use your part of the script and put the processEx.au3 in an #include <processEx.au3> in my sript it errors out with:

Error popup window title: _ProcessListEx - Error

Message body: There was an error to get ProcessList (@error = 3)

Any idea why that would happen?


-Tim

Share this post


Link to post
Share on other sites

Works fine here.

@error = 3 means: No processes found.

Are you sure the process you are looking for is still running?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I just need to find the path of the process.

#Include <WinAPIEx.au3>

$path = _WinAPI_GetModuleFileNameEx($Pid)

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0