
, or did the same with my amendment to the code.
Option Strict Off
Option Explicit On
Module Module1
Public Const PROCESS_ALL_ACCESS As Integer = &H1F0FFF
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer
Public Declare Function FindWindow Lib "USER32" Alias "FindWindowA"(ByVal Classname As String, ByVal WindowName As String) As Integer
Public Declare Function GetWindowThreadProcessId Lib "USER32" (ByVal hwnd As Integer, ByRef lpdwProcessId As Integer) As Integer
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot"(ByVal lFlags As Integer, ByVal lProcessID As Integer) As Integer
'UPGRADE_WARNING: Structure PROCESSENTRY32 may require marshalling attributes to be passed as an argument in this Declare statement. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="C429C3A5-5D47-4CD9-8F51-74A1616405DC"'
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Integer, ByRef uProcess As PROCESSENTRY32) As Integer
'UPGRADE_WARNING: Structure PROCESSENTRY32 may require marshalling attributes to be passed as an argument in this Declare statement. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="C429C3A5-5D47-4CD9-8F51-74A1616405DC"'
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Integer, ByRef uProcess As PROCESSENTRY32) As Integer
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Integer)
Private Structure PROCESSENTRY32
Dim dwSize As Integer
Dim cntUsage As Integer
Dim th32ProcessID As Integer
Dim th32DefaultHeapID As Integer
Dim th32ModuleID As Integer
Dim cntThreads As Integer
Dim th32ParentProcessID As Integer
Dim pcPriClassBase As Integer
Dim dwFlags As Integer
'UPGRADE_WARNING: Fixed-length string size must fit in the buffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="3C1E4426-0B80-443E-B943-0627CD55D48B"'
<VBFixedString(260),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,SizeConst:=260)> Public szExeFile() As Char
End Structure
Public Function GetHProcExe(ByRef strExeName As String) As Integer
Dim hSnap As Integer
'Create a snapshot of all of the processes, and information
'about them (saving the handle so we can iterate through the
'processes)
hSnap = CreateToolhelpSnapshot(2, 0)
Dim peProcess As PROCESSENTRY32
'UPGRADE_ISSUE: LenB function is not supported. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="367764E5-F3F8-4E43-AC3E-7FE0B5E074E2"'
peProcess.dwSize = System.Runtime.InteropServices.Marshal.SizeOf(peProcess)
Dim nProcess As Integer
nProcess = Process32First(hSnap, peProcess)
'Loop through the processes until we find the one we want
'and return its process handle
Do While nProcess
If StrComp(Trim(peProcess.szExeFile), strExeName, CompareMethod.Text) = 0 Then
GetHProcExe = OpenProcess(PROCESS_ALL_ACCESS, False, peProcess.th32ProcessID)
Exit Function
End If
peProcess.szExeFile = vbNullString
nProcess = Process32Next(hSnap, peProcess)
Loop
CloseHandle(hSnap)
End Function
Public Function FindProc(ByRef ProcName As String) As Integer
Dim hwnd As Integer
Dim ProcessID As Integer
Dim ProcessHandle As Integer
hwnd = FindWindow(vbNullString, ProcName)
GetWindowThreadProcessId(hwnd, ProcessID)
ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, False, ProcessID)
FindProc = ProcessHandle
End Function
End Module