'Todo este codigo en un modulo de Access o de VB
Option Compare Database
Option Explicit
Const TH32CS_SNAPHEAPLIST = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPTHREAD = &H4
Const TH32CS_SNAPMODULE = &H8
Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Const TH32CS_INHERIT = &H80000000
Const MAX_PATH As Integer = 260
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 * MAX_PATH
End Type
Private Declare Function CreateToolhelp32Snapshot Lib "Kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Process32First 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 Sub CloseHandle Lib "Kernel32" (ByVal hPass As Long)
Function BuscaEjecutableCargado(Nombre As String) As Boolean
'Nota del Búho:
'Esta funcion recibe un parametro Nombre,por ejemplo NOTEPAD.EXE y te dice
'si dicho ejecutable esta cargado o no, devolviendo un valor False o True
'Es una adapatación particular para tu caso concreto.
'Con este mismo ejemplo, puedes rellenar en un TXT todos los procesos
'que tiene activo Windows
Dim ValorBolean As Boolean, R
Dim hSnapShot As Long, uProcess As PROCESSENTRY32
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)
uProcess.dwSize = Len(uProcess)
R = Process32First(hSnapShot, uProcess)
Do While R
If UCase(Left$(uProcess.szExeFile, IIf(InStr(1, uProcess.szExeFile, Chr$(0)) > 0, InStr(1, uProcess.szExeFile, Chr$(0)) - 1, 0))) = UCase(Nombre) Then
MsgBox "Programa Encontrado en memoria"
ValorBolean = True
Exit Do
End If
R = Process32Next(hSnapShot, uProcess)
Loop
CloseHandle hSnapShot
BuscaEjecutableCargado = ValorBolean
End Function
'Fin de codigo
Para llamar a esta función desde cualquier Form, pon simplemente
lineas de la forma:
If BuscaEjecutableCargado("NOTEPAD.EXE")= True Then
msgbox "Esta cargado el Bloc de notas"
Else
msgbox "No esta cargado el Bloc de Notas"
End If
Saludos del Búho
               (
geocities.com/es/ensolva/Descargas)                   (
geocities.com/es/ensolva)                   (
geocities.com/es)