Vermutlich hilft dir das hier weiter: http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework/topic23427.aspx
Jedenfalls klappt das bei mir mit folgendem Code:
Option Explicit On
Option Strict On
Imports System.Runtime.InteropServices
Public Partial Class MainForm
'---- 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( _
ByVal hProcess As Int32, _
ByVal lpBaseAddress As Int32, _
Byval lpBuffer() As Byte, _
ByVal nSize As Int32, _
ByRef lpNumberOfBytesRead As Int32 _
) As Int32
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
Public Sub New()
' The Me.InitializeComponent call is required for Windows Forms designer
' support.
Me.InitializeComponent()
'
' TODO : Add constructor code after InitializeComponents
'
End Sub
Sub Button1Click(ByVal sender As Object, ByVal e As EventArgs)
Dim p As Process() = Process.GetProcessesByName("Explorer")
If p.Length = 0 Then
MessageBox.Show("Process not found", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
Exit Sub
End If
Dim proc As IntPtr = New IntPtr(OpenProcess( _
ProcessAccessPriviledges.PROCESS_VM_READ, 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(255) As Byte
Dim written As integer
Do
Try
' Hier wird buffer auf Nothing gesetzt und written auf 0 ...
ReadProcessMemory(proc.ToInt32(), addr, buffer, buffer.Length, _
written)
Debug.WriteLine(System.Text.Encoding.Default.GetString(buffer))
Catch ex As Exception
Debug.WriteLine("ReadProcessMemory: " & ex.Message)
Exit Do
End Try
addr += &H100
Loop
End Sub
End Class |