[VB6.0] Processes, t path ervan.

Pagina: 1
Acties:

  • wallywally
  • Registratie: Maart 2004
  • Laatst online: 20-05 18:22
Dag GOT-ters.

Ik ben bezig met een prog aant schrijven in VB6. T gaat om een processviewer met de nodige api's uiteraard. Maar nu vroeg ik me af he.. ik post hier ff een stukje code :
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Public Sub display() 'looks for process currently running
    Dim hSnapshot As Long ' declare variables
    Dim processInfo As PROCESSENTRY32
    Dim success As Long
    Dim exeName As String
    Dim retval As Long
    Dim itm As ListItem
        
    hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0) 'get process snapshot handle
    processInfo.dwSize = Len(processInfo) 'set actual size for information
    success = Process32First(hSnapshot, processInfo) 'get first process info from snapshot handle
    If hSnapshot = -1 Then 'No process running
       Exit Sub
    End If
    items2 = 0 'It is used to refresh system only when new process is added or removed
    While success <> 0 'Count Total number of process currently running
          items2 = items2 + 1
          success = Process32Next(hSnapshot, processInfo)
    Wend
    retval = CloseHandle(hSnapshot) 'close handle
    If items1 <> items2 Then 'If new process present or removed display new information
       hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0) 'same old procedure to get latest process status
       processInfo.dwSize = Len(processInfo)
       success = Process32First(hSnapshot, processInfo)
       cnt = 1
       info.ListItems.Clear
       While success <> 0
             exeName = Left(processInfo.szExeFile, InStr(processInfo.szExeFile, vbNullChar) - 1)

             Set itm = info.ListItems.Add(cnt, , GetFileName(exeName)) 'Display result in listview
             itm.Tag = exeName
             itm.SubItems(1) = processInfo.th32ProcessID
             itm.SubItems(2) = processInfo.th32ParentProcessID
             itm.SubItems(3) = processInfo.cntThreads
             itm.SubItems(4) = processInfo.cntUsage
             itm.SubItems(5) = processInfo.th32ModuleID
             itm.SubItems(6) = processInfo.th32DefaultHeapID
             cnt = cnt + 1
             processInfo.dwSize = Len(processInfo)
             success = Process32Next(hSnapshot, processInfo)
       Wend
       retval = CloseHandle(hSnapshot)
       Label3.Caption = cnt - 1 & " Process Running" 'inform user with updated information
       items1 = items2 'assign new item count as old item count
     End If
End Sub


Hiermee haal je alle processen in een listview, werkt opzich heel aardig. Maar met EXEname krijg ik alleen de naam van de EXE. Wat ik nu zoek.. is het hele path, waar de exe staat dus. Is er een manier om dit te zoeken via het process? Want met processinfo kan je niet veel meer als alleen de exename opzoeken.

BvD.

Edit : Sorry voor de layoutfuck :(

[ Voor 4% gewijzigd door wallywally op 02-11-2004 19:47 . Reden: layoutfok ]


  • RayNbow
  • Registratie: Maart 2003
  • Laatst online: 22:20

RayNbow

Kirika <3

Dit is wat ik vond op een site:
The toolhelp functions can be used everywhere except NT4. The problem is that while the toolhelp functions do return the full file path in win9x, they only return the file NAME in the winNT family. So if you need the full path in the NT family you need to use PsApi.dll. This works in the whole winNT family, but not in win9x.
Addendum:
De PsApi.dll API calls zijn EnumProcesses, EnumProcessModules, GetModuleFileNameEx en GetProcessMemoryInfo

[ Voor 12% gewijzigd door RayNbow op 02-11-2004 20:13 . Reden: Addendum ]

Ipsa Scientia Potestas Est
NNID: ShinNoNoir


  • wallywally
  • Registratie: Maart 2004
  • Laatst online: 20-05 18:22
Geweldig man, ben eruit. Heel erg bedankt.