Blue Theme Orange Theme Green Theme Red Theme
 
Discover the top 5 tips for understanding .NET Interop
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Nevron Chart
Search :       Advanced Search »
Home » C# Language » C# and Win32_PortConnector Class

C# and Win32_PortConnector Class

In this article you will learn how to use Different available port connector in a computer system using C# and Win32_PortConnector Class.

Author Rank :
Page Views : 3289
Downloads : 93
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
Port_info.zip
 
 
DevExpress Free UI Controls
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


Win32_PortConnector Class:

It represents physical connection port Like Parallel Port ECP/EPP, Serial Port XT/AT Compatible SCSI Port,MIDI Port, Joy Stick Port, Keyboard Port, Mouse Port.

See the structure of Win32_PortConnector Class

class Win32_PortConnector : CIM_PhysicalConnector
{
string Caption;
string ConnectorPinout;
uint16 ConnectorType[];
string CreationClassName;
string Description;
string ExternalReferenceDesignator;
datetime InstallDate;
string InternalReferenceDesignator;
string Manufacturer;
string Model;
string Name;
string OtherIdentifyingInfo;
string PartNumber;
uint16 PortType;
boolean PoweredOn;
string SerialNumber;
string SKU;
string Status;
string Tag;
string Version;
};

You can understand property easily by its name.

Example: Serial Number represents the serial number of particular.

Here we basically explain the type of Port using property PortType.

And it returns the value of type uint16.

So the return value and its meaning is given in following table:

Values Meaning
0 None
1 Parallel Port XT/AT Compatible
2 Parallel Port PS/2
3 Parallel Port ECP
4 Parallel Port EPP
5 Parallel Port ECP/EPP
6 Serial Port XT/AT Compatible
7 Serial Port 16450 Compatible
8 Serial Port 16550 Compatible
9 Serial Port 16550A Compatible
10 SCSI Port
11 MIDI Port
12 Joy Stick Port
13 Keyboard Port
14 Mouse Port
15 SSA SCSI
16 USB
17 FireWire (IEEE P1394)
18 PCMCIA Type II
19 PCMCIA Type II
20 PCMCIA Type III
21 CardBus
22 Access Bus Port
23 SCSI II
24 SCSI Wide
25 PC-98
26 PC-98-Hireso
27 PC-H98
28 Video Port
29 Audio Port
30 Modem Port
31 Network Port
32 8251 Compatible
33 8251 FIFO Compatible

Here is your code:

       private void button1_Click(object sender, EventArgs e)
        {
            Dictionary<UInt16, string> dict = new Dictionary<ushort, string>();
            dict.Add(0,"None");
            dict.Add(1,"Parallel Port XT/AT Compatible");
            dict.Add(2,"Parallel Port PS/2");
            dict.Add(3,"Parallel Port ECP");
            dict.Add(4,"Parallel Port EPP");
            dict.Add(5,"Parallel Port ECP/EPP");
            dict.Add(6,"Serial Port XT/AT Compatible");
            dict.Add(7,"Serial Port 16450 Compatible");
            dict.Add(8,"Serial Port 16550 Compatible");
            dict.Add(9,"Serial Port 16550A Compatible");
            dict.Add(10,"SCSI Port");
            dict.Add(11,"MIDI Port");
            dict.Add(12,"Joy Stick Port");
            dict.Add(13,"Keyboard Port");
            dict.Add(14,"Mouse Port");
            dict.Add(15,"SSA SCSI ");
            dict.Add(16,"USB");
            dict.Add(17,"FireWire (IEEE P1394)");
            dict.Add(18,"PCMCIA Type II");
            dict.Add(19,"PCMCIA Type II");
            dict.Add(20,"PCMCIA Type III");
            dict.Add(21,"CardBus");
            dict.Add(22,"Access Bus Port");
            dict.Add(23,"SCSI II");
            dict.Add(24,"SCSI Wide");
            dict.Add(25,"PC-98");
            dict.Add(26,"PC-98-Hireso");
            dict.Add(27,"PC-H98");
            dict.Add(28,"Video Port");
            dict.Add(29,"Audio Port");
            dict.Add(30,"Modem Port");
            dict.Add(31,"Network Port");
            dict.Add(32,"8251 Compatible");
            dict.Add(33,"8251 FIFO Compatible");

            var mos = new ManagementObjectSearcher();
            mos.Query = new ObjectQuery("SELECT * FROM Win32_PortConnector");
            foreach (ManagementObject mo in mos.Get())
            {
 
                    listBox1.Items.Add(dict[Convert.ToUInt16(mo["PortType"])]);

            }

        }

Dictionary is used to give meaning to the result with some messages.

The output will be as:

Port.gif

From above you can easily find the available ports. You can see that there is 4 usb ports, 1 for keyboard, 1 for mouse and etc.

Hope you understand it.

Thank you.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Hiren Soni
http://dotnetask.com
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the Top 5 .NET Memory Management Fundamentals
To write the best .NET code, you need to know exactly how the .NET framework really manages memory. Ricky Leeks presents the Top 5 fundamental facts of .NET memory management. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Comments
Discover the top 5 tips for understanding .NET Interop
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.