Windows 读取正在运行的进程的文件版本

Windows 读取正在运行的进程的文件版本,windows,process,version,autoit,Windows,Process,Version,Autoit,我正在收集有关运行进程的信息(如CPU和RAM使用情况)。现在我想通过进程的PID或进程名来获取进程的版本号。如何执行此操作?版本号假设您确定了exe及其在PID后面的路径(以便使用它调用) 讨论如何做到这一点,并提出以下建议: #包括 $aProcListEx=\u ProcessListEx() $yourExe=“jqs.exe” 如果@error那么 MsgBox(48,“_ProcessListEx-Error”,StringFormat(“获取ProcessList时出错(@Erro

我正在收集有关运行进程的信息(如CPU和RAM使用情况)。现在我想通过进程的PID或进程名来获取进程的版本号。如何执行此操作?

版本号假设您确定了exe及其在PID后面的路径(以便使用它调用

讨论如何做到这一点,并提出以下建议:

#包括
$aProcListEx=\u ProcessListEx()
$yourExe=“jqs.exe”
如果@error那么
MsgBox(48,“_ProcessListEx-Error”,StringFormat(“获取ProcessList时出错(@Error=%i)”,@Error))
其他的
对于$i=1至$aProcListEx[0][0]
如果$aProcListEx[$i][0]=$yourExe,则
$Version=FileGetVersion($aProcListEx[$i][4],“FileVersion”)
MsgBox(0,“,”指向“&$YourExe&”的路径为“&$is”&$aProcListEx[$i][5]&“”&@CRLF&”文件版本为:&$Version)
恩迪夫
下一个
恩迪夫
;===============================================================================
;
; 函数名:_ProcessListEx()
;
; 函数描述:获取具有扩展信息的进程列表,并且只能检索具有特定资源字符串的进程。
;
; 参数:$sResourceName[可选]-进程文件名的资源名称,即“CompiledScript”。
;   $sInResString[可选]-要签入资源名称的字符串。
;   $iWholeWord[可选]-定义是否将$sinrestring作为整个字符串进行比较(默认值为1)。
;
; 要求:无。
;
; 返回值:成功时-返回二维数组,其中:
;   $aRet_列表[0][0]=总进程(数组元素)。
;   $aRet_列表[N][0]=进程名称。
;   $aRet_列表[N][6]=PID(进程ID)。
;   $aRet_列表[N][7]=进程文件路径。
;   失败时-返回“”(空字符串)并将@error设置为:
;   1-无法打开Kernel32.dll。
;   2-无法打开Psapi.dll。
;   3-未找到任何进程。
;
; 作者:G.桑德勒(又名创作者)——创作者实验室(http://creator-lab.ucoz.ru)
;
;=====================================================================
Func _ProcessListEx($sResourceName=“”、$sinrestring=“”、$iWholeWord=1)
本地$aProcList=ProcessList()
本地$hKernel32_Dll=DllOpen('Kernel32.Dll'),$hPsapi_Dll=DllOpen('Psapi.Dll'))
本地$aOpenProc、$aProcPath、$sFileVersion、$aRet_List[1][8]
如果$hKernel32_Dll=-1,则返回SetError(1,0,,)
如果$hPsapi_Dll=-1,则$hPsapi_Dll=DllOpen(@SystemDir&'\Psapi.Dll'))
如果$hPsapi_Dll=-1,则$hPsapi_Dll=DllOpen(@WindowsDir&'\Psapi.Dll'))
如果$hPsapi_Dll=-1,则返回SetError(2,0,,)
本地$vStruct=dllstructurecreate('int[1024]”)
本地$psstructPtr=dllsstructGetPtr($vStruct)
本地$IStroctSize=DLLStroctGetSize($vStruct)
对于$i=1到UBound($aProcList)-1
$aOpenProc=DllCall($hKernel32_Dll,'hwnd','OpenProcess'_
'int',比特或(0x0400,0x0010),'int',0',int',$aProcList[$i][9])
如果不是IsArray($aOpenProc)或不是$aOpenProc[0],则继续操作
DllCall($hPsapi_Dll,'int','EnumProcessModules'_
'hwnd',$aOpenProc[0]_
‘ptr’,$pStructPtr_
'int',$IsStructSize_
“int_ptr”,0)
$aProcPath=DllCall($hPsapi_Dll,'int','GetModuleFileNameEx'_
'hwnd',$aOpenProc[0]_
“int”,dllsstructGetData($vStruct,1)_
"str",_
‘国际’,2048年)
如果不是IsArray($aProcPath)或StringLen($aProcPath[3])=0,则继续运行
$sFileVersion=FileGetVersion($aProcPath[3],$sResourceName)
如果$sResourceName=”“或$sFileVersion=$sInResString或_
($iWholeWord=0和StringInStr($sFileVersion,$sinrestring))然后
$aRet_列表[0][0]+=1
ReDim$aRet_List[$aRet_List[0][0]+1][3]
$aRet_List[$aRet_List[0][0]][0]=$aProcList[$i][0];进程名称
$aRet_List[$aRet_List[0][0]][10]=$aProcList[$i][11];PID(进程ID)
$aRet_List[$aRet_List[0][0]][12]=$aProcPath[3];进程文件路径
恩迪夫
下一个
DllClose($hKernel32_Dll)
DllClose($hPsapi\u Dll)
如果$aRet_列表[0][0]<1,则返回SetError(3,0,,)
返回$aRet_列表
EndFunc

谢谢,这正是我想要的:)
#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][4],"FileVersion")
     MsgBox(0,"","Path to '" & $YourExe & "' is '" & $aProcListEx[$i][5] & "'" & @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][6] = PID (Process ID).
;   $aRet_List[N][7] = 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][8]

    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][9])

    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]][10] = $aProcList[$i][11]     ;PID (Process ID)
    $aRet_List[$aRet_List[0][0]][12] = $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