Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to get the tray button text wiht ReadProcessMemory
    primarykey
    data
    text
    <p>I want to get all tray icons on windows7(64bit) with C#,but when i used the windows api "ReadProcessMemory" ,the tray button Text can't be recognied. codes below</p> <pre><code> IntPtr pid = IntPtr.Zero; IntPtr ipHandle = IntPtr.Zero; IntPtr lTextAdr = IntPtr.Zero; IntPtr ipTray = TrayToolbarWindow32(); WinApiHelper.GetWindowThreadProcessId(ipTray, ref pid); if (pid.Equals(0)) return iconList; IntPtr hProcess = WinApiHelper.OpenProcess(WinApiHelper.PROCESS_ALL_ACCESS | WinApiHelper.PROCESS_VM_OPERATION | WinApiHelper.PROCESS_VM_READ | WinApiHelper.PROCESS_VM_WRITE, IntPtr.Zero, pid); IntPtr lAddress = WinApiHelper.VirtualAllocEx(hProcess, 0, 4096, WinApiHelper.MEM_COMMIT, WinApiHelper.PAGE_READWRITE); int lButton = WinApiHelper.SendMessage(ipTray, WinApiHelper.TB_BUTTONCOUNT, 0, 0); for (int i = 0; i &lt; lButton; i++) { WinApiHelper.SendMessage(ipTray, WinApiHelper.TB_GETBUTTON, i, lAddress); WinApiHelper.ReadProcessMemory(hProcess, (IntPtr)(lAddress.ToInt32() + 16), ref lTextAdr, 4, 0); if (!lTextAdr.Equals(-1)) { byte[] buff = new byte[ 1024 ]; WinApiHelper.ReadProcessMemory(hProcess, lTextAdr, buff, 1024, 0); string title = System.Text.ASCIIEncoding.Unicode.GetString(buff); </code></pre> <p>and api declaration</p> <pre><code> [DllImport("kernel32", EntryPoint = "ReadProcessMemory")] public static extern int ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, ref IntPtr lpBuffer, int nSize, int lpNumberOfBytesWritten); [DllImport("kernel32.dll", EntryPoint = "ReadProcessMemory")] public static extern bool ReadProcessMemoryEx(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, IntPtr size, out IntPtr lpNumberOfBytesRead); [DllImport("kernel32", EntryPoint = "ReadProcessMemory")] public static extern int ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] lpBuffer, int nSize, int lpNumberOfBytesWritten); [DllImport("kernel32.dll")] public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, IntPtr lpBuffer, UIntPtr nSize, IntPtr lpNumberOfBytesRead); </code></pre> <p>the problem is here</p> <pre><code>string title = System.Text.ASCIIEncoding.Unicode.GetString(buff); </code></pre> <p>when converted , the string "title" can't be recognized,it maybe like </p> <pre><code>ǎ\0\0\0\0Д\0\0à\0\0ƿ\r\0\0\0\0\0\0\0\0\0\0D:\\Tools\\ESET Smart Security\\egui.exe\0\0\0\0\0\0\0\0\0\0\0\0\0\ </code></pre> <p>i don't know why, help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload