Kirjautuminen

Haku

Tehtävät

Keskustelu: Koodit: VB6: Hae Prosessit

tesmu [23.06.2006 03:04:02]

#

Elikkäs tämä hakee prosessin nimet... Toisin kuin Antin vinkissä se hakee prosessejen captionit.

Tarvitset Listboxin (processes) ja Commandbuttonin(Prosessit)

Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long

Const TH32CS_SNAPHEAPLIST = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPTHREAD = &H4
Const TH32CS_SNAPMODULE = &H8
Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Const TH32CS_INHERIT = &H80000000
Const MAX_PATH As Integer = 260
Private Type PROCESSENTRY32
    dwSize As Long
    cntUsage As Long
    th32ProcessID As Long
    th32DefaultHeapID As Long
    th32ModuleID As Long
    cntThreads As Long
    th32ParentProcessID As Long
    pcPriClassBase As Long
    dwFlags As Long
    szExeFile As String * MAX_PATH
End Type

Sub Prosessit_Click()
GetProcesses
End Sub

Sub GetProcesses()
    Dim hSnapShot As Long, uProcess As PROCESSENTRY32
    'otetaan "snapshotti" prosessista
    hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)
    'prosessikahvan pituus tjtnsp
    uProcess.dwSize = Len(uProcess)
    'info prosessin koosta

    r = Process32First(hSnapShot, uProcess)

    Do While r
    'haetaan ja lisäillään prosessit
        r = Process32Next(hSnapShot, uProcess)
        processes.AddItem uProcess.szExeFile
    Loop
    'suljetaan kahva
    CloseHandle hSnapShot
     'otetaan eka ja vika prosessi pois koska eka on "[System]" ja toinen on joku lopetusmerkki
    processes.RemoveItem (0)
    processes.RemoveItem (list.processes.ListCount - 1)
End Sub

Vastaus

Aihe on jo aika vanha, joten et voi enää vastata siihen.

Tietoa sivustosta