GeoAvila (Geovanny G. Avila) Desarrollo.. de software.

2Jul/080

Saber si un Proceso esta Ejecutandose desde Visual Basic 6

Hola,bueno este codigo lo que hace es chequear si un proceso esta corriendo o no,usa una funcion que retorna un valor Boolean(verdadero o falso) segun se detecte si se esta ejecutandose...en este caso al apretar un boton chequea como proceso la calculadora de windows cuyo nombre de proceso es CALC.EXE, ustedes reemplazenlo por el que quieran saber...

Visual Basic:
  1. Option Explicit
  2. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
  3. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  4. Private Declare Function EnumProcesses Lib "PSAPI.DLL" (lpidProcess As Long, ByVal cb As Long, cbNeeded As Long) As Long
  5. Private Declare Function EnumProcessModules Lib "PSAPI.DLL" (ByVal hProcess As Long, lphModule As Long, ByVal cb As Long, lpcbNeeded As Long) As Long
  6. Private Declare Function GetModuleBaseName Lib "PSAPI.DLL" Alias "GetModuleBaseNameA" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
  7. Private Const PROCESS_VM_READ = &H10
  8. Private Const PROCESS_QUERY_INFORMATION = &H400
  9.  
  10. Private Function EstaCorriendo(ByVal NombreDelProceso As String) As Boolean
  11. Const MAX_PATH As Long = 260
  12. Dim lProcesses() As Long, lModules() As Long, N As Long, lRet As Long, hProcess As Long
  13. Dim sName As String
  14. NombreDelProceso = UCase$(NombreDelProceso)
  15. ReDim lProcesses(1023) As Long
  16. If EnumProcesses(lProcesses(0), 1024 * 4, lRet) Then
  17. For N = 0 To (lRet \ 4) - 1
  18. hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, lProcesses(N))
  19. If hProcess Then
  20. ReDim lModules(1023)
  21. If EnumProcessModules(hProcess, lModules(0), 1024 * 4, lRet) Then
  22. sName = String$(MAX_PATH, vbNullChar)
  23. GetModuleBaseName hProcess, lModules(0), sName, MAX_PATH
  24. sName = Left$(sName, InStr(sName, vbNullChar) - 1)
  25. If Len(sName) = Len(NombreDelProceso) Then
  26. If NombreDelProceso = UCase$(sName) Then EstaCorriendo = True: Exit Function
  27. End If
  28. End If
  29. End If
  30. CloseHandle hProcess
  31. Next N
  32. End If
  33. End Function
  34.  
  35. Private Sub Command1_Click()
  36. MsgBox EstaCorriendo("calc.exe")
  37. End Sub

saludos.

No TweetBacks yet. (Be the first to Tweet this post)
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.

Sigueme en Twitter

Recent Posts

Amigos de Twitter

LibrosyMasgt
yoasumo
TuFrac
guilleybruno
ChapinGeek
Luckysilva
guatecham
Elultimodepaz
f0vela
tuxtor
barcampgt
giopack
emisorasunidas
gjprensalibre
xarquis
andreimorales
robertogt
Miguel_gt
jhony88
omarvelz
prensa_libre
tuiterasgt
SweetPickles_
monikgtr
edyn81
flashvio
cancuengt
el_Periodico
dneevi
alexxx007
libelulablu
N3T1O
loopix
Waphy
rebezuniga
fher33
Friends: 300 Followers: 360

Categories

Sitios amigos

Algunos Derechos Reservados

Blog bajo licencia Creative Commons Attribution-ShareAlike 3.0 License
Creative Commons License