I'm trying to retrieve the index of "explorer.exe" in Task Manager, but the index keeps returning -1, although it is in there...
Does anyone know what's wrong?Code:Imports System.Runtime.InteropServices Public Declare Auto Function FindWindow Lib "user32" Alias "FindWindowW" (ByVal sClassName As String, ByVal sWindowName As String) As IntPtr Public Declare Auto Function FindWindowEx Lib "user32" Alias "FindWindowExW" (ByVal ipParent As IntPtr, ByVal ipChildAfter As IntPtr, ByVal sClassName As String, ByVal sWindowName As String) As IntPtr Public Declare Auto Function SendMessage Lib "user32" Alias "SendMessageW" (ByVal ipWindow As IntPtr, ByVal iMsg As Integer, ByVal ipWParam As IntPtr, ByVal ipLParam As IntPtr) As Integer #Region " [LVFINDINFO] " Public Structure LVFINDINFO Dim flags As UInteger Dim psz As String Dim lParam As IntPtr Dim pt As Point Dim vkDirection As UInteger End Structure #End Region Public Const LVFI_STRING As Integer = 2 Public Const LVM_FINDITEM As Integer = 4179 Public ipHandle As IntPtr = IntPtr.Zero Public ipDialog As IntPtr = IntPtr.Zero Public ipListView As IntPtr = IntPtr.Zero Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim pTask() As Process = Process.GetProcessesByName("taskmgr") If pTask.Length <= 0 Then Return End If Dim pProcess As Process = pTask(0) ipHandle = pProcess.MainWindowHandle ipDialog = FindWindowEx(ipHandle, Nothing, Nothing, Nothing) ipListView = FindWindowEx(ipDialog, Nothing, "SysListView32", "Processes") Dim lvfiInfo As New LVFINDINFO() lvfiInfo.flags = LVFI_STRING lvfiInfo.psz = "explorer.exe" Dim ipPointer As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(lvfiInfo)) Marshal.StructureToPtr(lvfiInfo, ipPointer, True) Dim iIndex As Integer = SendMessage(ipListView, LVM_FINDITEM, CType(-1, IntPtr), ipPointer) End Sub
Cheers
Icyculyr




Reply With Quote