question

HemanthB-9452 avatar image
1 Vote"
HemanthB-9452 asked JunjieZhu-MSFT edited

Launch the Service Controller App from C# WinUI 3

How do I launch the Service Controller App that is part of the MMC from C# WinUI 3 app?

windows-app-sdk
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JunjieZhu-MSFT avatar image
0 Votes"
JunjieZhu-MSFT answered JunjieZhu-MSFT edited

Hello,
Welcome to Microsoft Q&A!

The Service Controller App can be opened by calling the cmd Process(System.Diagnostics) in C#.

 Process CmdProcess = new Process();
 CmdProcess.StartInfo.FileName = "cmd.exe";

 CmdProcess.StartInfo.CreateNoWindow = true;        
 CmdProcess.StartInfo.UseShellExecute = false;      
 CmdProcess.StartInfo.RedirectStandardInput = true;   
 CmdProcess.StartInfo.RedirectStandardOutput = true;    
 CmdProcess.StartInfo.RedirectStandardError = true;  

 CmdProcess.StartInfo.Arguments = "/c " + "services.msc"; //“/C”Indicates to exit immediately after executing the command  
 CmdProcess.Start();
 CmdProcess.StandardOutput.ReadToEnd();//get return value   
 CmdProcess.WaitForExit();//Wait for the program to finish executing and exit the process
 CmdProcess.Close();//END

205984-gif-2022-5-27-11-12-39.gif

Thank you.


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.