e intentado con:
Código:
dim recogidadedatos as string, handle as long
handle=openprocess( information or read,0, id)
getwindowtext(handle,recogidadedatos,100)
msgbox(recogidadedatos)
handle=openprocess( information or read,0, id)
getwindowtext(handle,recogidadedatos,100)
msgbox(recogidadedatos)
Pero parece que no encuentra el handle. Alguien me puede explicar el motivo?
A ¡¡, En el proceso vb leido con openprocess me da un handle pero en otro programa me sale otro handle en el mismo proceso.
Este es el modulo que lista los procesos en un treeview y pone en handle el classname y las dependencias:
Código:
Public Function FillProcessListNT(treeview As MSComctlLib.treeview) As Long
'=========================================================
'Clears the listbox specified by the DestListBox parameter
'and then fills the list with the processes and the
'modules used by each process
'=========================================================
Dim cb As Long
Dim cbNeeded As Long
Dim NumElements As Long
Dim ProcessIDs() As Long
Dim cbNeeded2 As Long
Dim NumElements2 As Long
Dim Modules(1 To 1024) As Long
Dim lRet As Long
Dim ModuleName As String
Dim nSize As Long
Dim hProcess As Long
Dim i As Long
Dim sModName As String
Dim sChildModName As String
Dim iModDlls As Long
Dim iProcesses As Integer
Dim nodo(5) As Node
treeview.Nodes.Clear
Set nodo(0) = treeview.Nodes.Add(, , , "Procesos en ejecucion")
'Get the array containing the process id's for each process object
cb = 8
cbNeeded = 96
'One important note should be made. Although the documentation
'names the returned DWORD "cbNeeded", there is actually no way
'to find out how big the passed in array must be. EnumProcesses()
'will never return a value in cbNeeded that is larger than the
'size of array value that you passed in the cb parameter.
'if cbNeeded == cb upon return, allocate a larger array
'and try again until cbNeeded is smaller than cb.
Do While cb <= cbNeeded
cb = cb * 2
ReDim ProcessIDs(cb / 4) As Long
lRet = EnumProcesses(ProcessIDs(1), cb, cbNeeded)
Loop
'calculate how many process IDs were returned
NumElements = cbNeeded / 4
For i = 1 To NumElements
'Get a handle to the Process
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION _
Or PROCESS_VM_READ, 0, ProcessIDs(i))
' Iterate through each process with an ID that <> 0
If hProcess Then
'Retrieve the number of bytes that the array of module handles requires
lRet = EnumProcessModules(hProcess, Modules(1), 1024, cbNeeded2)
'Get an array of the module handles for the specified process
lRet = EnumProcessModules(hProcess, Modules(1), cbNeeded2, cbNeeded2)
'If the Module Array is retrieved, Get the ModuleFileName
If lRet <> 0 Then
'Fill the ModuleName buffer with spaces
ModuleName = Space(MAX_PATH)
'Preset buffer size
nSize = 500
'Get the module file name
lRet = GetModuleFileNameExA(hProcess, Modules(1), ModuleName, nSize)
frmModuleList.Text1.Text = Modules(1)
'Get the module file name out of the buffer, lRet is how
'many characters the string is, the rest of the buffer is spaces
sModName = Left$(ModuleName, lRet)
'Add the process to the listbox
Set nodo(1) = treeview.Nodes.Add(nodo(0), tvwChild, , sModName, "false")
treeview.Nodes.Add nodo(1), tvwChild, , "Class name :"
treeview.Nodes.Add nodo(1), tvwChild, , "Pid :" & ProcessIDs(i)
treeview.Nodes.Add nodo(1), tvwChild, , "Hwnd :" & hProcess
Set nodo(2) = treeview.Nodes.Add(nodo(1), tvwChild, , "Dependencias")
'Increment the count of processes we've added
iProcesses = iProcesses + 1
iModDlls = 1
Do
iModDlls = iModDlls + 1
'Fill the ModuleName buffer with spaces
ModuleName = Space(MAX_PATH)
'Preset buffer size
nSize = 500
'Get the module file name out of the buffer, lRet is how
'many characters the string is, the rest of the buffer is spaces
lRet = GetModuleFileNameExA(hProcess, Modules(iModDlls), ModuleName, nSize)
sChildModName = Left$(ModuleName, lRet)
If sChildModName = sModName Then Exit Do
If Trim(sChildModName) <> "" Then treeview.Nodes.Add nodo(2), tvwChild, , sChildModName, "false"
Loop
End If
Else
'Return the number of Processes found
FillProcessListNT = 0
End If
'Close the handle to the process
lRet = CloseHandle(hProcess)
Next
'Return the number of Processes found
FillProcessListNT = iProcesses
End Function
'=========================================================
'Clears the listbox specified by the DestListBox parameter
'and then fills the list with the processes and the
'modules used by each process
'=========================================================
Dim cb As Long
Dim cbNeeded As Long
Dim NumElements As Long
Dim ProcessIDs() As Long
Dim cbNeeded2 As Long
Dim NumElements2 As Long
Dim Modules(1 To 1024) As Long
Dim lRet As Long
Dim ModuleName As String
Dim nSize As Long
Dim hProcess As Long
Dim i As Long
Dim sModName As String
Dim sChildModName As String
Dim iModDlls As Long
Dim iProcesses As Integer
Dim nodo(5) As Node
treeview.Nodes.Clear
Set nodo(0) = treeview.Nodes.Add(, , , "Procesos en ejecucion")
'Get the array containing the process id's for each process object
cb = 8
cbNeeded = 96
'One important note should be made. Although the documentation
'names the returned DWORD "cbNeeded", there is actually no way
'to find out how big the passed in array must be. EnumProcesses()
'will never return a value in cbNeeded that is larger than the
'size of array value that you passed in the cb parameter.
'if cbNeeded == cb upon return, allocate a larger array
'and try again until cbNeeded is smaller than cb.
Do While cb <= cbNeeded
cb = cb * 2
ReDim ProcessIDs(cb / 4) As Long
lRet = EnumProcesses(ProcessIDs(1), cb, cbNeeded)
Loop
'calculate how many process IDs were returned
NumElements = cbNeeded / 4
For i = 1 To NumElements
'Get a handle to the Process
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION _
Or PROCESS_VM_READ, 0, ProcessIDs(i))
' Iterate through each process with an ID that <> 0
If hProcess Then
'Retrieve the number of bytes that the array of module handles requires
lRet = EnumProcessModules(hProcess, Modules(1), 1024, cbNeeded2)
'Get an array of the module handles for the specified process
lRet = EnumProcessModules(hProcess, Modules(1), cbNeeded2, cbNeeded2)
'If the Module Array is retrieved, Get the ModuleFileName
If lRet <> 0 Then
'Fill the ModuleName buffer with spaces
ModuleName = Space(MAX_PATH)
'Preset buffer size
nSize = 500
'Get the module file name
lRet = GetModuleFileNameExA(hProcess, Modules(1), ModuleName, nSize)
frmModuleList.Text1.Text = Modules(1)
'Get the module file name out of the buffer, lRet is how
'many characters the string is, the rest of the buffer is spaces
sModName = Left$(ModuleName, lRet)
'Add the process to the listbox
Set nodo(1) = treeview.Nodes.Add(nodo(0), tvwChild, , sModName, "false")
treeview.Nodes.Add nodo(1), tvwChild, , "Class name :"
treeview.Nodes.Add nodo(1), tvwChild, , "Pid :" & ProcessIDs(i)
treeview.Nodes.Add nodo(1), tvwChild, , "Hwnd :" & hProcess
Set nodo(2) = treeview.Nodes.Add(nodo(1), tvwChild, , "Dependencias")
'Increment the count of processes we've added
iProcesses = iProcesses + 1
iModDlls = 1
Do
iModDlls = iModDlls + 1
'Fill the ModuleName buffer with spaces
ModuleName = Space(MAX_PATH)
'Preset buffer size
nSize = 500
'Get the module file name out of the buffer, lRet is how
'many characters the string is, the rest of the buffer is spaces
lRet = GetModuleFileNameExA(hProcess, Modules(iModDlls), ModuleName, nSize)
sChildModName = Left$(ModuleName, lRet)
If sChildModName = sModName Then Exit Do
If Trim(sChildModName) <> "" Then treeview.Nodes.Add nodo(2), tvwChild, , sChildModName, "false"
Loop
End If
Else
'Return the number of Processes found
FillProcessListNT = 0
End If
'Close the handle to the process
lRet = CloseHandle(hProcess)
Next
'Return the number of Processes found
FillProcessListNT = iProcesses
End Function