|
|||
|
Hola, NECESITO DE SU AYUDA
, tengo una duda,lo que quiero es una forma de detectar los procesos que se ejecutan, y mande un mensaje.Por ejemplo: - Selecciono un archivo desde el "Explorador de Windows": Y el programa debe mostrar "Seleccionaste 'Nombre del Archivo' - Borro ese archivo: Y el programa debe mostrar "Borraste el archivo" o tambien - Dar click con el raton sobre mi PC por ejemplo. y que el programa diga "Seleccionaste Mi PC" - O al dar doble click sobre la papelera de reciclaje, muestre un mensaje que diga "Entraste a la papelera de reciclaje" Esto es posible!? Llevo dias investigando y no encuentro nada ...
__________________
"Una máquina puede hacer el trabajo de 50 hombres corrientes. Pero no existe ninguna máquina que pueda hacer el trabajo de un hombre extraordinario." |
|
||||
|
Hola que tal, mira hay un ejemplo en el cual enumeran los procesos y dependiendo del programa que selecciones le impide su ejecucion.
http://www.recursosvisualbasic.com.a...ocesos_wmi.htm |
|
|||
|
Hola Dark_soul , ese ejemplo hace otra cosa, pero no es lo que pretende hacer Drakun ...que es algo bastante complicado de hacer
Pd: hola Leandro, probé el ejemplo, pero la función ( l a que está dentro del Timer) me devuelve siempre un vbnullstring, ¿ te faltó algún pedaso de código? o yo hice algo mal ?? saludos |
|
||||
|
Cita:
aca esta buscando el handle Código:
Option Explicit
Private Type LVITEM
mask As Long
iItem As Long
iSubitem As Long
state As Long
stateMask As Long
pszText As Long
cchTextMax As Long
iImage As Long
lParam As Long
iIndent As Long
End Type
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
Private Declare Function VirtualFreeEx Lib "kernel32" (ByVal hProcess As Long, lpAddress As Any, ByVal dwSize As Long, ByVal dwFreeType As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Const LVIF_IMAGE = &H2
Private Const LVIF_TEXT = &H1
Private Const LVM_FIRST As Long = &H1000
Private Const LVM_GETITEM As Long = (LVM_FIRST + 5)
Private Const LVM_GETITEMCOUNT = (LVM_FIRST + 4)
Private Const LVM_GETITEMSTATE = (LVM_FIRST + 44)
Private Const LVIS_SELECTED = &H2
Private Const PAGE_READWRITE = &H4&
Private Const MEM_RESERVE = &H2000
Private Const MEM_COMMIT = &H1000
Private Const MEM_RELEASE = &H8000
Private Const PROCESS_VM_OPERATION = &H8
Private Const PROCESS_VM_READ = &H10
Private Const PROCESS_VM_WRITE = &H20
Dim Handle As Long
Private Sub Form_Load()
Dim i As Integer
Me.AutoRedraw = True
Handle = FindWindow("Progman", vbNullString)
Handle = FindWindowEx(Handle, ByVal 0&, "SHELLDLL_DefView", vbNullString)
Handle = FindWindowEx(Handle, ByVal 0&, "SysListView32", "FolderView")
If Handle <> 0 Then
For i = 0 To GetListViewCount(Handle) - 1
Me.Print ListViewGetText(Handle, 0, i)
Next i
Timer1.Interval = 2000
Else
MsgBox "No se encontro el listview - SysListView32 -"
End If
End Sub
Private Function ListViewGetText(ByVal hwnd As Long, ByVal iSubitem As Integer, ByVal iItem As Integer) As String
Dim lngProcID As Long, lngProcHandle As Long
Dim typLvItem As LVITEM, strLvItem As String
Dim lngVarPtr1 As Long, lngVarPtr2 As Long
Dim lngMemVar1 As Long, lngMemVar2 As Long
Dim lngMemLen1 As Long, lngMemLen2 As Long
Call GetWindowThreadProcessId(hwnd, lngProcID)
If lngProcID <> 0 Then
lngProcHandle = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, False, lngProcID)
If lngProcHandle <> 0 Then
strLvItem = String(255, vbNullChar)
lngVarPtr1 = StrPtr(strLvItem)
lngVarPtr2 = VarPtr(typLvItem)
lngMemLen1 = LenB(strLvItem)
lngMemLen2 = LenB(typLvItem)
lngMemVar1 = VirtualAllocEx(lngProcHandle, 0, lngMemLen1, MEM_RESERVE Or MEM_COMMIT, PAGE_READWRITE)
lngMemVar2 = VirtualAllocEx(lngProcHandle, 0, lngMemLen2, MEM_RESERVE Or MEM_COMMIT, PAGE_READWRITE)
With typLvItem
.cchTextMax = 255
.iItem = iItem
.iSubitem = iSubitem
.mask = LVIF_TEXT
.pszText = lngMemVar1
End With
Call WriteProcessMemory(lngProcHandle, ByVal lngMemVar1, ByVal lngVarPtr1, lngMemLen1, 0)
Call WriteProcessMemory(lngProcHandle, ByVal lngMemVar2, ByVal lngVarPtr2, lngMemLen2, 0)
Call SendMessage(hwnd, LVM_GETITEM, ByVal 0, ByVal lngMemVar2)
Call ReadProcessMemory(lngProcHandle, ByVal lngMemVar1, ByVal lngVarPtr1, lngMemLen1, 0)
strLvItem = StrConv(strLvItem, vbUnicode)
strLvItem = Left(strLvItem, InStr(1, strLvItem, vbNullChar) - 1)
ListViewGetText = strLvItem
Call VirtualFreeEx(lngProcHandle, ByVal lngMemVar1, lngMemLen1, MEM_RELEASE)
Call VirtualFreeEx(lngProcHandle, ByVal lngMemVar2, lngMemLen2, MEM_RELEASE)
Call CloseHandle(lngProcHandle)
End If
End If
End Function
Function GetListViewCount(ByVal hwnd As Long) As Long
'this simply get number of items
GetListViewCount = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, ByVal 0)
End Function
Function GetItemSelected(hwnd As Long) As Long
Dim i As Long, Index As Long
For i = 1 To GetListViewCount(hwnd)
Index = SendMessage(hwnd, LVM_GETITEMSTATE, i - 1, ByVal LVIS_SELECTED)
If Index > 0 Then
GetItemSelected = i
Exit For
End If
Next
End Function
Private Sub Timer1_Timer()
Dim Index As Long
Index = GetItemSelected(Handle) - 1
Me.Caption = ListViewGetText(Handle, 0, Index)
End Sub
|
|
|||
|
Hola,
Si ahora me toma bien el Listview del escritorio y me actualiza los datos en el caption del form Para actualizar los elementos ( el listado de items en el form ) se puede llamar al procedimeinto del formload y ponerlo en el timer Código:
Private Sub Timer1_Timer() Dim Index As Long Dim i As Integer Index = GetItemSelected(Handle) - 1 Me.Caption = ListViewGetText(Handle, 0, Index) Cls For i = 0 To GetListViewCount(Handle) - 1 Me.Print ListViewGetText(Handle, 0, i) Next i End Sub saludos |
|
|||
|
Gracias, muchas gracias, no sabes cuanto tiempo llevo intentando hacer un codigo asi, lo probare y te escribire mis resultado muchas gracias Leandro.
__________________
"Una máquina puede hacer el trabajo de 50 hombres corrientes. Pero no existe ninguna máquina que pueda hacer el trabajo de un hombre extraordinario." |
![]() |
| Herramientas | Buscar en Tema |
| Desplegado | |
|
|
Temas Similares
|
||||
| Tema | Autor | Foro | Respuestas | Último mensaje |
| escritorio o web | point | General | 0 | 20-Jun-2008 14:17 |
| Enumerar claves del registro | Lliterola | Visual Basic 6.0 | 0 | 21-Dec-2006 00:33 |
| Directorio del escritorio | Guests | Visual Basic 6.0 | 4 | 19-Sep-2006 09:19 |
| Actualizar escritorio | Guests | Visual Basic 6.0 | 2 | 22-Aug-2006 03:19 |
| Icono al escritorio | Guests | Visual Basic 6.0 | 3 | 15-Jul-2006 21:12 |