循环所有进程内存

时间:2011-06-21 14:55:04

标签: api memory vb6 process

我怎么能使用“ReadProcessMemory”API循环遍历机器的所有正在运行的进程并扫描一个字符串数组并返回一个真/假值,如果进程的内存中包含任何一个或多个 - 使用VB6?

示例:

Strings() = {"@STRING1@", "@ANOTHERSTRING@", "$TRING"}
Loop # Processes
    If InStr(ProcessMemory(#), Strings) Then
        MsgBox(Process(#) & " Contains one of the strings!")
    End If
Loop

1 个答案:

答案 0 :(得分:1)

我不知道,但我在我的程序中使用了wmi

是怎么回事

Public Sub KillProcess(ByVal processName As String)

On Error GoTo ErrHandler

Dim oWMI
Dim ret
Dim sService
Dim oWMIServices
Dim oWMIService
Dim oServices
Dim oService
Dim servicename

Set oWMI = GetObject("winmgmts:")
Set oServices = oWMI.InstancesOf("win32_process")

For Each oService In oServices

    servicename = LCase$(Trim$(CStr(oService.Name) & ""))

    If InStr(1, servicename, LCase(processName), vbTextCompare) > 0 Then
        ret = oService.Terminate
    End If

Next

If Not oServices Is Nothing Then Set oServices = Nothing
If Not oWMI Is Nothing Then Set oWMI = Nothing


ErrHandler:
    Err.Clear

End Sub