How to open notepad on remote computer

MIPAKTEH_1 545 Reputation points
2025-02-11T08:11:09.79+00:00

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.Diagnostics;

using System.Management;

namespace WMI_

{

public partial class Form1 : Form

{

    public Form1()

    {

        InitializeComponent();

    }

    private void Form1_Load(object sender, EventArgs e)

    {

        ConnectionOptions options = new ConnectionOptions();

        options.Username = "xxx";

        options.Password = "xxx";

        options.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);

        scope.Options.EnablePrivileges = true;

        scope.Connect();

        ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Process");

        using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query))

        {

            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 calculator process

            ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);

            // Get process ID

            uint processId = (uint)outParams["processId"];

            Console.WriteLine($"Calculator process started with Process ID: {processId}");

        }

    }

}
```}

Remote Desktop
Remote Desktop
A Microsoft app that connects remotely to computers and to virtual apps and desktops.
4,713 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,286 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Rohit Khandelwal 0 Reputation points
    2025-02-11T13:27:27.8633333+00:00

    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}");
            }
        }
    }
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.