how to change the port description in device manager programatically in c#?
Port name description changing
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
how to change the port description in device manager programatically in c#?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ajay KumarRank #56 · 29K reputationPosted Sep 22, 2023, 7:26 AM EDT
using System; using System.Management; class Program { static void Main() { string portName = "COM3"; // Replace with the COM port you want to modify string newDescription = "New Port Description"; // Replace with the new description you want // Set up a query to find the COM port by name string query = $"SELECT * FROM Win32_PnPEntity WHERE Name = '{portName}'"; // Create a management object searcher using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query)) { // Get the COM port ManagementObjectCollection collection = searcher.Get(); foreach (ManagementObject device in collection) { try { // Change the description device["Description"] = newDescription; device.Put(); // Save changes Console.WriteLine($"Port description for {portName} changed to {newDescription}"); } catch (Exception ex) { Console.WriteLine($"Error changing port description: {ex.Message}"); } } } } }