Click here to Skip to main content
16,016,925 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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.Management;

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


        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                ManagementObjectSearcher MOSearcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSSerial_PortName");

                foreach (ManagementObject MOject in MOSearcher.Get())
                {
                    listBox1.Items.Add(MOject["InstanceName"]);//MSSerial_PortName instance
                    listBox1.Items.Add(MOject["PortName"]);//MSSerial_PortName instance

                    //If the serial port's instance name contains USB it must be a USB to serial device
                    if (MOject["InstanceName"].ToString().Contains("USB"))
                    {
                        listBox1.Items.Add(MOject["PortName"] + " is a USB to Serial Adapter/Converter");
                    }
                }
            }
            catch (ManagementException me)
            {
                MessageBox.Show("An error occurred while querying for WMI data: " + me.Message);
            }
        }
    }
}


I'm having the folowing code. This works with windows xp. When i run it in windows 7 it doesn't. How is that possible? Error: not supported ??
Posted
Updated 17-Dec-13 5:43am
v2
Comments
Richard MacCutchan 17-Dec-13 12:02pm    
What line causes the error?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900