_______________________________
Printable View
_______________________________
hi
this is my code
and when use this code remote program is teminated
can anyone help me?Code:
Option Explicit
Private Type LV_ITEM
mask As Long
iItem As Long
iSubItem As Long
state As Long
stateMask As Long
pszText As String
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
Const LVM_FIRST = &H1000
Const LVM_GETITEM = (LVM_FIRST + 5)
Const LVIF_IMAGE = &H2
Const LVIF_TEXT = &H1
Private Sub Command1_Click()
Dim myItem As LV_ITEM
With myItem
.iItem = 0 '<-- 1'st Listitem (zero based index)
.iSubItem = 0 '<-- one based; set to 0 to refer to Item
.pszText = String(256, vbNullChar) '<-- Allocate buffer space for Item text
.cchTextMax = 256 '<-- Length of buffer
.mask = LVIF_IMAGE Or LVIF_TEXT
End With
SendMessage (hwn of remote program), LVM_GETITEM, 0&, myItem
'Remove null char's from Item text string
myItem.pszText = Replace(myItem.pszText, vbNullChar, "")
MsgBox "Item Text: " & myItem.pszText
End Sub
Threads merged - please post each question (or variation of it) only once.
Processes are running i virtual memory, i.e. all starts at address &H400000. You har requesting information from a remote process which will retrieve the data from a non existing listview structure. As I understand you have got the remote window handle already. This is how you do it.
1. Allocate memory in remote process
2. Fill your listview structre with values as you have done
3. Transfer the structure to allocated memory in remote process
4. Send the message but this time with address to allocated memory i remote process
5. Transfer the item text from allocated memory in remote process to allocated memory in your process
6. Free allocated memory
Now you can show messagebox with item text.
hey men help meQuote:
Originally Posted by minor28
this is another,i find this but when get item only empty added to listbox?
why?
Code:Option Explicit
Private Const LVIF_TEXT As Long = &H1
Private Const LVM_FIRST As Long = &H1000
Private Const LVM_GETITEM As Long = (LVM_FIRST + 5)
Private Const LVM_SETITEM As Long = (LVM_FIRST + 6)
Private Const LVM_GETITEMCOUNT As Long = (LVM_FIRST + 4)
Private Const MEM_COMMIT As Long = &H1000
Private Const PAGE_READWRITE As Long = &H4
Private Const STANDARD_RIGHTS_REQUIRED As Long = &HF0000
Private Const SYNCHRONIZE As Long = &H100000
Private Const PROCESS_ALL_ACCESS As Long = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)
Private Const MEM_RELEASE As Long = &H8000
Private Type LVITEM
mask As Long
iItem As Long
iSubItem As Long
state As Long
stateMask As Long
pszText As Long 'Notice not string but long
cchTextMax As Long
iImage As Long
lParam As Long
iIndent As Long
End Type
Private Declare Function OpenProcess Lib "kernel32.dll" ( _
ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32.dll" ( _
ByVal hProcess As Long, _
ByRef lpBaseAddress As Any, _
ByRef lpBuffer As Any, _
ByVal nSize As Long, _
ByRef lpNumberOfBytesWritten As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32.dll" ( _
ByVal hProcess As Long, _
ByRef lpBaseAddress As Any, _
ByRef lpBuffer As Any, _
ByVal nSize As Long, _
ByRef lpNumberOfBytesWritten As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32.dll" ( _
ByVal hwnd As Long, _
ByRef lpdwProcessId As Long) As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As Long, _
ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" ( _
ByVal hwndParent As Long, _
ByVal hwndChildAfter As Long, _
ByVal lpszClass As String, _
ByVal lpszWindow As Long) As Long
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Declare Function VirtualAllocEx Lib "kernel32.dll" ( _
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.dll" ( _
ByVal hProcess As Long, _
ByVal lpAddress As Long, _
ByVal dwSize As Long, _
ByVal dwFreeType As Long) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" ( _
ByVal hObject As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32.dll" ( _
ByVal hProcess As Long, _
ByVal uExitCode As Long) As Long
Dim hProcess As Long
Private Sub Command1_Click()
Dim hndl As Long
Dim hListView As Long
Dim lpdwProcessId As Long
Dim pMem As Long
Dim lvi As LVITEM
Dim lpNumberOfBytesWritten As Long
Dim i As Long
Dim cItems As Long
Dim txt As String
Dim pTxt As Long
'Get the handle of listview control
hndl = FindWindow(0, "WindowName")
hListView = FindWindowEx(hndl, 0, "SysListView32", 0)
'Retrieve a handle of the listview control process
GetWindowThreadProcessId hListView, lpdwProcessId
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, lpdwProcessId)
'Allocate memory in listview process memory space for the LVITEM structure and listitem text
pMem = VirtualAllocEx(hProcess, 0, Len(lvi), MEM_COMMIT, PAGE_READWRITE)
pTxt = VirtualAllocEx(hProcess, 0, 256, MEM_COMMIT, PAGE_READWRITE)
'Retrieve number of listview items
cItems = SendMessage(hListView, LVM_GETITEMCOUNT, 0, 0)
'Fill a LVITEM structure with values
lvi.mask = LVIF_TEXT
lvi.cchTextMax = 256
lvi.pszText = pTxt 'This is a pointer to the address where item text will be hold
'Allocate space for a string
txt = Space(256)
For i = 0 To cItems - 1
'Add item index to structure
lvi.iItem = i
'Transfer the structure to allocated memory in listview memory space
WriteProcessMemory hProcess, ByVal pMem, lvi, Len(lvi), lpNumberOfBytesWritten
'Send message to get listview item [i]. Result hold in LVITEM strucktur at address pMem
SendMessage hListView, LVM_GETITEM, 0, ByVal pMem
'Transfer the item text from allocated memory at pTxt to txt space in this app process memory
ReadProcessMemory hProcess, ByVal pTxt, ByVal txt, 256, lpNumberOfBytesWritten
List1.AddItem txt
Next i
'Free allocated memory
VirtualFreeEx hProcess, pMem, Len(lvi), MEM_RELEASE
VirtualFreeEx hProcess, pTxt, 256, MEM_RELEASE
End Sub
Private Sub Form_Load()
Shell "fullpath to listview.exe"
End Sub
Private Sub Form_Terminate()
TerminateProcess hProcess, 0
CloseHandle hProcess
End Sub
please answer my ques!
I think the main problem is with this line of code
You have to supply the window's titlebar text of the window that contains the listview.Code:hndl = FindWindow(0, "WindowName")
Ensure hndl1 and hListView are not zero. If they are, you are not finding what you are looking for.
iknow, but its for example!Quote:
Originally Posted by LaVolpe
this attached file is my vb codes its work for taskmgr.exe and i SUCCESSFUL to get text from taskmgr.exe but not work for my remote program(RSDLite)
this link is my remote program >> http://www.4shared.com/file/23878331...te_39.html?s=1
when i get text from listview of rsdlite only empty give to me?
why?
help please
Have a look at this thread if it helps.
Quote:
Originally Posted by dee-u
i get text from taskmmgr.exe.its ok no problem but when get text from RSDlite listview, send error to me? (http://www.4shared.com/file/23878331...te_39.html?s=1)
help please
many thanks
I recognize the code. It looks like you have come across some of my code. This code is complete and should work. Of your answer to LaVolpe's suggestion I can't conclude that hnd1 or hListView are zero or not. I guess you haven't found the window.
Quote:
Originally Posted by minor28
thanks much
yes its work fine but woth some change
how to select with left mouse click on listview frist item?
What do you mean? Have you got the text from the listview or not. Is it a new question?Quote:
Originally Posted by Y.P.Y
yes i have got text from listview,Quote:
Originally Posted by minor28
this is new question:
How to send left click mouse button(WM_LBUTTON) message to items of listview?
i think must be create another Thread for my 2nd questions!!