也可以用try catch 抛出 e.tostring看看到底那一行的问题

解决方案 »

  1.   

    按钮按下后程序便停止响应了,根本不能抛出Exception
      

  2.   

    private void buttonXP1_Click(object sender, System.EventArgs e)
            {
               
                using(DirectoryEntry root = new DirectoryEntry("WinNT:"))//有错误;
                {
                    foreach(DirectoryEntry domain in root.Children)
                    {
                        listBox1.Items.Add(">>>"+domain.Name);
                        foreach(DirectoryEntry pc in domain.Children)
                        {
                            if(pc.Name != "Schema")
                                listBox1.Items.Add("    "+pc.Name);
                        }
                    }
                }
            }