please try below, it was working for me.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
ConnectionOptions options = new ConnectionOptions
{
Username = "xxx",
Password = "xxx",
Authority = "ntlmdomain:DESKTOP-RG6V063"
};
string remoteComputer = "xxx"; // Replace with the IP address or name of your remote computer
ManagementScope scope = new ManagementScope($"\\\\{remoteComputer}\\root\\cimv2", options)
{
Options = { EnablePrivileges = true }
};
scope.Connect();
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Process");
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query))
using (ManagementClass processClass = new ManagementClass(scope, new ManagementPath("Win32_Process"), new ObjectGetOptions()))
{
ManagementBaseObject inParams = processClass.GetMethodParameters("Create");
// Set the process path to be started
inParams["CommandLine"] = "Notepad.exe";
// Start the Notepad process
ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);
// Get process ID
uint processId = (uint)outParams["processId"];
Console.WriteLine($"Notepad process started with Process ID: {processId}");
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}