Hallo Leute,
ich möchte aus einem anderen Prozess einen Wert auslesen. Es soll nach Text gesucht werden und der direkt dahinter stehende dann ausgelesen werden.
Also z.B. nach "Endbetrag: " suchen und das auslesen, was dahinter steht.
Nun habe ich aber das Porblem, dass ReadProcessMemory() mir immer nur Nothing in den buffer schreibt.
Mein Code bisher sieht so aus:
(WindowsApplication2 ist einfach noch ein simples extra Programm zum Testen)
'---- API-Deklarationen ---------------------------
<DllImport("kernel32", CallingConvention:=CallingConvention.Winapi, _
EntryPoint:="OpenProcess", ExactSpelling:=True, SetLastError:=True)> _
Public Shared Function OpenProcess(<MarshalAs(UnmanagedType.U4)> ByVal _
DesiredAccess As ProcessAccessPriviledges, _
ByVal InheritHandle As Boolean, _
ByVal ProcessId As Int32) As Int32
End Function
<DllImport("kernel32", CallingConvention:=CallingConvention.Winapi, _
EntryPoint:="ReadProcessMemory", ExactSpelling:=True, _
SetLastError:=True)> _
Public Shared Function ReadProcessMemory( _
<InAttribute()> ByVal hProcess As Int32, _
<InAttribute()> ByVal lpBaseAddress As UInt32, _
<OutAttribute()> ByRef lpBuffer As Byte(), _
<InAttribute()> ByVal nSize As Int32, _
<OutAttribute()> ByRef lpNumberOfBytesRead As UInt32 _
) As Boolean
End Function
<Flags()> _
Public Enum ProcessAccessPriviledges
PROCESS_TERMINATE = &H1
PROCESS_CREATE_THREAD = &H2
PROCESS_SET_SESSIONID = &H4
PROCESS_VM_OPERATION = &H8
PROCESS_VM_READ = &H10
PROCESS_VM_WRITE = &H20
PROCESS_DUP_HANDLE = &H40
PROCESS_CREATE_PROCESS = &H80
PROCESS_SET_QUOTA = &H100
PROCESS_SET_INFORMATION = &H200
PROCESS_QUERY_INFORMATION = &H400
PROCESS_SYNCHRONISE = &H100000
PROCESS_ALL_ACCESS = &H100FFF
End Enum
'----------------------------------------------------------------------------
Dim p As Process() = Process.GetProcessesByName("WindowsApplication2")
If p.Length = 0 Then
MessageBox.Show("Process not found", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
Exit Sub
End If
Dim proc As IntPtr = OpenProcess( _
ProcessAccessPriviledges.PROCESS_ALL_ACCESS, False, p(0).Id)
If proc = IntPtr.Zero Then
MessageBox.Show("Could not open process", "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Dim addr As Int32 = 0
Dim buffer(1023) As Byte
Dim written As Long
Do
Try
' Hier wird buffer auf Nothing gesetzt und written auf 0 ...
ReadProcessMemory(proc, addr, buffer, buffer.Length, written)
Debug.WriteLine(buffer)
Catch ex As Exception
Debug.WriteLine("ReadProcessMemory: " & ex.Message)
Exit Do
End Try
addr += &H100
Loop Weiß jemand, was da falsch läuft? |