using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.IO.Ports; using System.Windows.Forms; using System.Management; namespace Detect_USB2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); SerialPort ComPort = new SerialPort(); chkSP(); } private void chkSP() { ManagementObjectSearcher searchType = new ManagementObjectSearcher("SELECT * FROM Win32_SerialPort"); foreach (ManagementObject moDiskete in searchType.Get()) { if (!listBox1.Items.Contains(moDiskete["Name"])) { listBox1.Items.Add(moDiskete["Name"].ToString()); } } } private void MyTimer_Tick(object sender, EventArgs e) { listBox1.Items.Clear(); chkSP(); } private void Form1_Load(object sender, EventArgs e) { Timer MyTimer = new Timer(); MyTimer.Interval = (5 * 1000); // 1 mins MyTimer.Tick += new EventHandler(MyTimer_Tick); MyTimer.Start(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)