Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6858993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:13:43+00:00 2026-05-27T02:13:43+00:00

In a C#.net console application, what code can i write to print on the

  • 0

In a C#.net console application, what code can i write to print on the screen the VID and PID of each USB device connected to the system?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:13:43+00:00Added an answer on May 27, 2026 at 2:13 am

    Here’s some code I’ve written based on what I’ve found so far. There may be a better way to do this.

        public static void MyMethod()
        {                            
            System.Management.ManagementClass USBClass = new ManagementClass("Win32_USBDevice");                
            System.Management.ManagementObjectCollection USBCollection = USBClass.GetInstances();
    
            foreach (System.Management.ManagementObject usb in USBCollection)
            {
                string deviceId = usb["deviceid"].ToString();
                Console.WriteLine(deviceId);
    
                int vidIndex = deviceId.IndexOf("VID_");
                string startingAtVid = deviceId.Substring(vidIndex + 4); // + 4 to remove "VID_"                    
                string vid = startingAtVid.Substring(0, 4); // vid is four characters long
                Console.WriteLine("VID: " + vid);
    
                int pidIndex = deviceId.IndexOf("PID_");
                string startingAtPid = deviceId.Substring(pidIndex + 4); // + 4 to remove "PID_"                    
                string pid = startingAtPid.Substring(0, 4); // pid is four characters long
                Console.WriteLine("PID: " + pid);                                        
            }            
    
            Console.ReadLine();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following sample code in a VB.NET console application. It compiles and
I have following requirement, I have C#/.Net console application, which refers to 'System.Data.Sqlite.dll' 'System.Data.Sqlite.dll'
I have a simple piece of code in a .NET console application that tries
When I run System.Diagnostics.Process.Start from my console application it works but the same code
I am starting a new instance of a console application from my .NET code
I have a .NET console application that needs to generate some HTML files. I
I have a .net Console Application called FooConsole. When I build and deploy it,
i've got a pretty simple .NET console application. I wish to pass in some
I am writing a VB.NET console application where it takes relative paths and spits
Is it possible to use a .net configuration file for a .NET console application?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.