Identificate a peripheral

M

MySelf

Hello,


I have an USB device connected to my PC. It emulates a COM port, so I
see a new COM port on my PC when device is connected.

Now, I would like to retrieve the name associated to that device in my
Windows Configuration Manager, to be able to check if the good
peripherals have been connected.

How can I achieve that in C# ?

Thanks.
 
M

MySelf

Après mûre réflexion, MySelf a écrit :
Hello,


I have an USB device connected to my PC. It emulates a COM port, so I see a
new COM port on my PC when device is connected.

Now, I would like to retrieve the name associated to that device in my
Windows Configuration Manager, to be able to check if the good peripherals
have been connected.

How can I achieve that in C# ?

Thanks.

OK, I found the answer here :
http://www.codeproject.com/KB/system/GetHardwareInformation.aspx

More specifically, use :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Management;

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

private void button1_Click(object sender, EventArgs e)
{
string[] theSerialPortNames = SerialPort.GetPortNames();

string s = "";
string portCom = "";
ManagementObjectSearcher searcher = new
ManagementObjectSearcher("select * from Win32_SerialPort");
var mo = searcher.Get();
foreach (ManagementObject share in mo)
{
if (share.Properties["Caption"] != null)
{
s = share.Properties["Caption"].Value.ToString();
}
}
}
}
}
 
M

MySelf

Dans son message précédent, MySelf a écrit :
Après mûre réflexion, MySelf a écrit :


PS : You can remove line :

string[] theSerialPortNames = SerialPort.GetPortNames();

I used it for a test and it is unnecessary for this case.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top