Open the device manager dialogue using csharp or xaml

geomeo123

Member
Joined
Apr 22, 2025
Messages
6
Programming Experience
1-3
As the title suggests is there an easy way to do this? The only ways I've found supposed to work with powershell and do not work. Here is one way I've tried, but it needs elevation. And I'm not sure how to do that......

C#:
var process = new Process
{
    StartInfo = new ProcessStartInfo("mmc.exe") { Verb = "runas", WindowStyle = ProcessWindowStyle.Hidden }

};
process.StartInfo.Arguments = "devmgmt.msc";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;

process.Start();

I'm currently using serial port devices which plug into the PC that Windows assigns a communications port number to. Ie com1, com2 com3 etc. Rather than ask the user to type in device manager at the search box in Windows I'm trying to put in a button so that it's one click away from my port select comboboxes.
 
What error are you getting?
 
And there you have it. You have to be running in an elevated context to launch mmc.exe.

In my experience, that "RunAs" verb doesn't work when UseShellExecute = false. You need to set it to true and disable all the redirects. In my opinion, the redirects are not doing you any good anyway since MMC is a graphical app, not a console app. I'm not sure if you'll even get any output to standard output or standard error.
 
Works without elevation:
C#:
Process.Start(new ProcessStartInfo("devmgmt.msc") { UseShellExecute = true});
 
Solution
John H that's the one with the new keyword! I typically use my example code with ping.exe, not mmc.exe, because I have some network adapters devices I have to set a static IPV4 address on the NIC so the devices can be used. It's a bit of a todo to figure out exactly which port a network device is plugged into when they don't have multiCastDNS, so I have that particular script already being used with the ping.exe command, that's why I tried that bit of script first, because I was thinking mmc.exe was close to ping.exe. (I don't know much about PowerShell to be honest) The other example that I was going to post here was on a forum as a "good answer", which was close to John H answer, but it didn't work. Best not to copy someone else's stupidity and just put my own up here lol.
As far as the no window thing goes, is because my ping.exe command pulls up a command prompt that I don't want the user to see. And some other stuff like adding an IPV4 address to an adapter.
Anyway, I appreciate y'alls effort to explain and answers!

Thank you!
 
Back
Top Bottom