O meu objetivo era finalizar processos. Consegui fazendo assim:
Private Const TH32CS_SNAPALL = &HF
Private Const PROCESS_TERMINATE As Long = &H1
Private Const PROCESS_ALL_ACCESS As Long = &H1F0FFF
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * 260
End Type
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Process32Min Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Private Declare Function GetModuleFileNameExA Lib "PSAPI.DLL" (ByVal hProcess As Long, ByVal hModule As Long, ByVal ModuleName As String, ByVal nSize As Long) As Long
Private Declare Function EnumProcessModules Lib "PSAPI.DLL" (ByVal hProcess As Long, ByRef lphModule As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
Public Sub FecharProcessos()
Dim ListaP As Long, DadosP As PROCESSENTRY32
Dim R As Long, ExeNome As String, Phnd As Long
Dim Modulos(255) As Long, Tamanho As Long
Dim Cod As Long
ListaP = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0)
If ListaP > -1 Then
DadosP.dwSize = Len(DadosP)
R = Process32Min(ListaP, DadosP)
If R Then
While R
Phnd = OpenProcess(PROCESS_ALL_ACCESS, 0, DadosP.th32ProcessID)
If EnumProcessModules(Phnd, Modulos(0), 256, Tamanho) <> 0 Then
ExeNome = String$(256, Chr$(0))
GetModuleFileNameExA Phnd, Modulos(0), ExeNome, 256
ExeNome = Replace(ExeNome, Chr$(0), "")
If ExeNome <> Caminho Then
GetExitCodeProcess Phnd, Cod
TerminateProcess Phnd, Cod
End If
End If
CloseHandle Phnd
R = Process32Next(ListaP, DadosP)
Wend
End If
CloseHandle ListaP
End If
End Sub