using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void Form1_Load(object sender, EventArgs e)
        {            Process[] proc = Process.GetProcesses();
            foreach (Process p in proc)
            {
                Console.WriteLine(p.MainWindowHandle.ToString());
            }
        }
    }
}上面是得到所有进程的主窗口句柄