「Windows タスク マネージャー」プロセス リストからすべての項目を取得して、アプリケーションのリストボックスに追加しようとしています。タスク マネージャーでプロセス リストのハンドルを取得するコードを見つけました。また、インデックスを使用してリストからアイテムを削除するコードがあります (正しいハンドルがあることをテストする良い方法です)。しかし、プロセスリスト内のアイテムの総数を取得し、そこのインデックスでアイテムを取得するには、C# コードが必要です。すべてのアイテムを順番に並べてリストボックスに追加するだけで解決します。
編集:コメントありがとうございます。詳しく説明します...プロセスをリストするだけではありません。それ以外の場合は、 System.Diagnostics.Process.GetProcesses(); を使用します。タスクマネージャーで並べ替えられている方法でプロセスを並べ替えたい。タスク マネージャーには、プロセスを並べ替えるさまざまな方法があります。それを行うための約31の異なる方法を提供します。例: イメージ名、PID、ユーザー名、CPU 使用率など。私の目的は、タスク マネージャーで並べ替えられた順序でプロセスを取得することです。
    static Int32 LVM_FIRST = 4096;
    static Int32 LVM_DELETEITEM = (LVM_FIRST + 8);
    static Int32 LVM_SORTITEMS = (LVM_FIRST + 48);
    [DllImport("user32.dll", EntryPoint = "FindWindowA")]
    private static extern Int32 apiFindWindow(string lpClassName, string lpWindowName);
    [DllImport("user32.dll", EntryPoint = "FindWindowExA")]
    private static extern Int32 apiFindWindowEx(Int32 hWnd1, Int32 hWnd2, string lpsz1, string lpsz2);
    [DllImport("user32.dll", EntryPoint = "SendMessageA")]
    private static extern Int32 apiSendMessage(Int32 hWnd, Int32 wMsg, Int32 wParam, string lParam);
    [DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
    private static extern Int32 apiGetDesktopWindow();
    void GetItems()
    {
        Int32 lhWndParent = apiFindWindow(null, "Windows Task Manager");
        Int32 lhWndProcessList = 0;
        Int32 lhWndDialog = 0;
        for (int i = 1; (i <= 7); i++)
        {
            // Loop through all seven child windows, for handle to the listview
            lhWndDialog = apiFindWindowEx(lhWndParent, lhWndDialog, null, null);
            if ((lhWndProcessList == 0))
            {
                lhWndProcessList = apiFindWindowEx(lhWndDialog, 0, "SysListView32", "Processes");
            }
        }
        /* This code removes the first item in the Task Manager Processes list:
         * apiSendMessage(lhWndProcessList, LVM_DELETEITEM, 0, "0");
         * note that the 3rd paramiter: 0, is the index of the item to delete.
         * I put it here in comments because I thought there would be
         * something similar to get the name*/
        listBox1.Items.Clear();
        int TotalItemCount = /*Total item count in Task Manager Processes list*/;
        for (int i = 0; i < TotalItemCount; i++)
        {
            listBox1.Items.Add(/*Get item  in Task Manager Processes list by index: i*/)
        }
    }