Open the device manager dialogue using csharp or xaml

geomeo123

Member
Joined
Apr 22, 2025
Messages
5
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});
 
Back
Top Bottom