Перейти из форума на сайт.

НовостиФайловые архивы
ПоискАктивные темыТоп лист
ПравилаКто в on-line?
Вход Забыли пароль? Первый раз на этом сайте? Регистрация
Компьютерный форум Ru.Board » Компьютеры » Программы » AutoIT (Часть 2)

Модерирует : gyra, Maz

Widok (01-06-2010 13:08): Лимит страниц. Продолжаем здесь.  Версия для печати • ПодписатьсяДобавить в закладки
На первую страницук этому сообщениюк последнему сообщению

   

sproxy



Full Member
Редактировать | Профиль | Сообщение | ICQ | Цитировать | Сообщить модератору


Код:
$iParent_ProcID = _ProcessGetParent(@AutoItPID) ; PID родительсого процесса
$sParent_ProcID_Path = _ProcessGetPath($iParent_ProcID) ; Полный адрес исполняемоего файла родительсого процесса
$sParent_ProcID_Disc_Path = StringLeft($sParent_ProcID_Path, 3) ; Диск, на котором расположен исполняемый файл родительсого процесса
$sParent_ProcID_Disc_Type = DriveGetType($sParent_ProcID_Disc_Path) ; Тип диска, на котором расположен исполняемый файл родительсого процесса
$sParent_ProcID_Disc_Name = DriveGetLabel($sParent_ProcID_Disc_Path) ; Название диска, на котором расположен исполняемый файл родительсого процесса
 
MsgBox(64,  'Родительский процесс', _
            'PID:'  & @TAB & @TAB & $iParent_ProcID & @CRLF & _
            'Путь:' & @TAB & @TAB & $sParent_ProcID_Path & @CRLF & _
            'Диск:' & @TAB & @TAB & $sParent_ProcID_Disc_Path & @CRLF & _
            'Тип диска:' & @TAB & $sParent_ProcID_Disc_Type & @CRLF & _
            'Название диска:' & @TAB & $sParent_ProcID_Disc_Name)
 
;=================================================================
; Function Name:    _ProcessGetParent()
;
; Description:      Retrieve parent process for a child process
;
; Parameter(s):     $i_pid: The process identifier of the process you want to get the parent
;                       process identifier for
;
; Return Value(s):
;                 On Success:
;                   Parent PID (process identifier)
;
;                 On Failure:
;                   PID of process passed (Check @error to make sure it is a parent and didn't
;                       fail)
;
;                 @Error:
;                   (1): CreateToolhelp32Snapshot failed
;                   (2): Process32First failed
;
; Remark(s):        Tested on Windows XP SP2
;
; Author(s):        SmOke_N (Ron Nielsen)
;
;==========================================================================

Func _ProcessGetParent($i_Pid)
    Local Const $TH32CS_SNAPPROCESS = 0x00000002
 
    Local $a_tool_help = DllCall("Kernel32.dll", "long", "CreateToolhelp32Snapshot", "int", $TH32CS_SNAPPROCESS, "int", 0)
    If IsArray($a_tool_help) = 0 Or $a_tool_help[0] = -1 Then Return SetError(1, 0, $i_Pid)
 
    Local $tagPROCESSENTRY32 = DllStructCreate( _
            "dword dwsize;" & _
            "dword cntUsage;" & _
            "dword th32ProcessID;" & _
            "uint th32DefaultHeapID;" & _
            "dword th32ModuleID;" & _
            "dword cntThreads;" & _
            "dword th32ParentProcessID;" & _
            "long pcPriClassBase;" & _
            "dword dwFlags;" & _
            "char szExeFile[260]")
 
    DllStructSetData($tagPROCESSENTRY32, 1, DllStructGetSize($tagPROCESSENTRY32))
 
    Local $p_PROCESSENTRY32 = DllStructGetPtr($tagPROCESSENTRY32)
 
    Local $a_pfirst = DllCall("Kernel32.dll", "int", "Process32First", "long", $a_tool_help[0], "ptr", $p_PROCESSENTRY32)
    If IsArray($a_pfirst) = 0 Then Return SetError(2, 0, $i_Pid)
 
    Local $a_pnext, $i_return = 0
 
    If DllStructGetData($tagPROCESSENTRY32, "th32ProcessID") = $i_Pid Then
        $i_return = DllStructGetData($tagPROCESSENTRY32, "th32ParentProcessID")
        DllCall("Kernel32.dll", "int", "CloseHandle", "long", $a_tool_help[0])
 
        If $i_return Then Return $i_return
        Return $i_Pid
    EndIf
 
    While
1
        $a_pnext = DllCall("Kernel32.dll", "int", "Process32Next", "long", $a_tool_help[0], "ptr", $p_PROCESSENTRY32)
        If IsArray($a_pnext) And $a_pnext[0] = 0 Then ExitLoop
        If
DllStructGetData($tagPROCESSENTRY32, "th32ProcessID") = $i_Pid Then
            $i_return = DllStructGetData($tagPROCESSENTRY32, "th32ParentProcessID")
            If $i_return Then ExitLoop
            $i_return = $i_Pid
            ExitLoop
        EndIf
    WEnd
 
    If
$i_return = "" Then $i_return = $i_Pid
 
    DllCall("Kernel32.dll", "int", "CloseHandle", "long", $a_tool_help[0])
    Return $i_return
EndFunc
 
;===============================================================================
;
; Function Name:    _ProcessGetPath()
; Description:      Get the executable path of certain process.
;
; Parameter(s):     $vProcess - PID or name of a process.
;
; Requirement(s):   AutoIt v3.2.8.1 or higher.
;                   Kernel32.dll (included with Windows)
;                   Psapi.dll (included with most Windows versions)
;
; Return Value(s):  On Success - Returns full path to the executed process.
;                   On Failure - Returns -1 and sets @Error to:
;                                                               1 - Given process not exists.
;                                                               2 - Error to call Kernel32.dll.
;                                                               3 - Error to open Psapi.dll.
;                                                               4 - Unable to locate path of executed process,
;                                                                   (or can be other error related to DllCall).
;
; Author(s):        G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru)
;
;===============================================================================

Func _ProcessGetPath($vProcess)
    Local $iPID = ProcessExists($vProcess)
    If Not $iPID Then Return SetError(1, 0, -1)
 
    Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID)
    If Not IsArray($aProc) Or Not $aProc[0] Then Return SetError(2, 0, -1)
 
    Local $vStruct = DllStructCreate('int[1024]')
 
    Local $hPsapi_Dll = DllOpen('Psapi.dll')
    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(3, 0, '')
 
    DllCall($hPsapi_Dll, 'int', 'EnumProcessModules', _
        'hwnd', $aProc[0], _
        'ptr', DllStructGetPtr($vStruct), _
        'int', DllStructGetSize($vStruct), _
        'int_ptr', 0)
    Local $aRet = DllCall($hPsapi_Dll, 'int', 'GetModuleFileNameEx', _
        'hwnd', $aProc[0], _
        'int', DllStructGetData($vStruct, 1), _
        'str', '', _
        'int', 2048)
 
    DllClose($hPsapi_Dll)
 
    If Not IsArray($aRet) Or StringLen($aRet[3]) = 0 Then Return SetError(4, 0, '')
    Return $aRet[3]
EndFunc


Всего записей: 556 | Зарегистр. 21-11-2007 | Отправлено: 17:47 27-06-2009 | Исправлено: sproxy, 18:10 27-06-2009
   

На первую страницук этому сообщениюк последнему сообщению

Компьютерный форум Ru.Board » Компьютеры » Программы » AutoIT (Часть 2)
Widok (01-06-2010 13:08): Лимит страниц. Продолжаем здесь.


Реклама на форуме Ru.Board.

Powered by Ikonboard "v2.1.7b" © 2000 Ikonboard.com
Modified by Ru.B0ard
© Ru.B0ard 2000-2024

BitCoin: 1NGG1chHtUvrtEqjeerQCKDMUi6S6CG4iC

Рейтинг.ru