GSI

C# USB 인식 심플한 코드

C# 2009. 12. 15. 18:25 |


    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            bool bFind = false;

            // USB 상태 체크
            DriveInfo [] diArray = DriveInfo.GetDrives();
            foreach (DriveInfo di in diArray)
            {
                if (di.IsReady == true && di.DriveType == DriveType.Removable)
                {
                    bFind = true;
                    break;
                }
            }

            label1.Text = (bFind == true) ? "존재합니다." : "없습니다.";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Start();
        }
    }

Posted by gsi
: