Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21193

[VB6]Help about looping to all iexplore process name and process ID

$
0
0
I want to loop to all Process Name of "iexplore.exe" and their Process ID (PID) to get their Handle
I have the following code to get the Process ID of a process name, in this case I can only find one PID of "iexplore.exe" not looping to all Process ID of all "Internet Explorer" Processes, I need to loop to all Internet Explorer Process ID and execute a code to their Process ID. THank yoU
I found this code somewhere just search for it.
Code:

GetProcessId
Code:

Public Function GetProcessId(ByVal ProcessName As String) As Long
Dim hSnapShot As Long
Dim uProcess As PROCESSENTRY32
Dim success As Long
Dim ProcessId As Long

    hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)

    If hSnapShot = -1 Then Exit Function

    uProcess.dwSize = Len(uProcess)
    success = ProcessFirst(hSnapShot, uProcess)

    If success = 1 Then
        Do
            If LCase(VBA.Left$(uProcess.szExeFile, InStr(1, uProcess.szExeFile, Chr(0)) - 1)) = LCase(ProcessName) Then

              ProcessId = uProcess.th32ProcessID
             
              GetProcessId = ProcessId
              Exit Do
            End If
           
        Loop While ProcessNext(hSnapShot, uProcess)
    End If
    Call CloseHandle(hSnapShot)
    GetProcessId = ProcessId
End Function

'Here's my code to execute something
Private Sub tmr_Timer()
Dim ProcessName As String
    ProcessName = "iexplore.exe"  'find internet explorer process(es)
    Debug.Print "Process name: " & ProcessName & "; Process ID: " & GetProcessId(ProcessName)
    PID = GetProcessId(ProcessName) 'erorr here only one of the many internet explorer process id is printed and detected
 
PID = 'do something with a PID here
End Sub


and also is there a way to create a file system watcher in VB6 like in VB.NET , i want to create a file system watcher to watch all drives and file system changes like file created, renamed and deleted

Viewing all articles
Browse latest Browse all 21193

Trending Articles



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