Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1463

hook createProcess with wmi

$
0
0
Code:

Private Sub Command2_Click()
Check1.Value = 0
End Sub

Private Sub Command1_Click()
'ADD CONTROLS:Command1,Command2,List1,check1

Check1.Value = 1
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colProcesses = objWMIService.ExecNotificationQuery _
    ("SELECT * FROM __instancecreationevent " _
            & " Within 1 Where TargetInstance ISA 'Win32_Process'")
            On Error Resume Next
            Dim objProcess As Object
            Dim A As String
Do While Check1.Value = 1
    DoEvents
    If Check1.Value = 0 Then Exit Sub
    Set objProcess = Nothing
    Set objProcess = colProcesses.NextEvent(10)
        If Not objProcess Is Nothing Then
        A = objProcess.TargetInstance.Caption
    i = i + 1
    List1.AddItem i & "--" & A
    Debug.Print A
End If
    DoEvents
Loop
End Sub

This code will jam the process, it is better to use in multi-threading, there is also an event-based method:
Code:

Do While Check1.Value = 1
    Set objProcess = colProcesses.NextEvent()
  A = objProcess.TargetInstance.Caption
loop

.Caption :process exe name
.ParentProcessId who create it
.Handle IS PROCESS ID

With objProcess.TargetInstance
A = .Caption & "/" & .Handle & "/Create BY:" & .ParentProcessId
End With
'Notepad.exe/17964/Create BY:17744 (EXPLORER.EXE)

Viewing all articles
Browse latest Browse all 1463

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>