By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,374 Members | 1,768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,374 IT Pros & Developers. It's quick & easy.

WriteProcessMemory not working (VB2005)

P: 63
Hi all,

In my previous topic about a week ago on this forum I attempted to use ReadProcessMemory. After several hours of trying different things, It worked. Next up I tried figuring out WriteProcessMemory. I was hoping that after hours of trying things, it would work. Unfortunately, I can't seem to get this one to work, and also my search on the internet resulted nothing useful.

I got this code, which in my eyes should work without any errors, but VB proves me wrong.

What it should do is pretty simple; press T, encode a message from a listbox from ASCII to Bytes, and write it, Then press Enter.

Expand|Select|Wrap|Line Numbers
  1. Private Sub timerC_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerC.Tick
  2.         Const WM_KEYDOWN = &H100
  3.         Const WM_KEYUP = &H101
  4.         Const VK_T = &H54
  5.         Const VK_RETURN = &HD
  6.         Dim hwnd, hprocess, idprocess As Integer
  7.         Dim Automsg As String
  8.         Static msg As Integer
  9.  
  10.         If msg = listC.Items.Count - 1 Then msg = -1
  11.         msg = msg + 1
  12.  
  13.         hwnd = FindWindow(vbNullString, windowname.Text)
  14.         If hwnd < 0 Or hwnd > 0 Then
  15.  
  16.             SendMessage(hwnd, WM_KEYDOWN, VK_T, 0&)
  17.             SendMessage(hwnd, WM_KEYUP, VK_T, 0&)
  18.  
  19.             Wait(120)
  20.  
  21.             GetWindowThreadProcessId(hwnd, idprocess)
  22.             hprocess = OpenProcess(PROCESS_ALL_ACCESS, False, idprocess)
  23.             Automsg = msg
  24.  
  25.             System.Text.Encoding.ASCII.GetBytes(Automsg)
  26.             WriteProcessMemory(hprocess, &H875F34, Automsg, 59, 0&)
  27.             CloseHandle(hprocess)
  28.  
  29.             Wait(120)
  30.  
  31.             SendMessage(hwnd, WM_KEYDOWN, VK_RETURN, 0&)
  32.             SendMessage(hwnd, WM_KEYUP, VK_RETURN, 0&)
  33.  
  34.         ElseIf hwnd = 0 Then
  35.             MsgBox("Cannot find " & windowname.Text), MsgBoxStyle.Critical, "Error!")
  36.             timerC.Enabled = False
  37.             Exit Sub
  38.         End If
  39.  
  40.     End Sub
  41.  
I just can't seem to figure out where the problem is, since it doesn't give any errors.
Though, it doesn't write to memory nor press Enter. It does press T but that's all there is.
Could anyone help fixing my code ?

Any help is appreciated.

Thanks in advance,
Evolution445
Sep 25 '07 #1
Share this Question
Share on Google+
2 Replies


P: 63
Anyone has any idea on solving this ?
Thanks
Sep 29 '07 #2

P: 63
I re-attempted the code again, this time thinking it only writes one character per WriteProcessMemory action.

Expand|Select|Wrap|Line Numbers
  1.         Dim AutomsgByte As Byte
  2.             Automsg = msg
  3.             For i As Integer = 0 To Automsg.Length
  4.                 System.Text.Encoding.ASCII.GetBytes(Automsg)
  5.                 Automsg = AutomsgByte
  6.                 WriteProcessMemory(hprocess, &H471E58, AutomsgByte, 59, 0&)
  7.             Next i
  8.  
Still no result.
If anyone knows how to fix my problem, please let me know.
Thanks!
Sep 30 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.