How to open notepad on remote computer

MIPAKTEH_1 605 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}");

        }

    }

}
```}

Windows for business | Windows Client for IT Pros | User experience | Remote desktop services and terminal services
Developer technologies | C#
Developer technologies | 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.
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    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}");
            }
        }
    }
    
    

  2. Bruce (SqlWork.com) 81,971 Reputation points Volunteer Moderator
    2025-02-11T16:34:37.6366667+00:00

    notepad is a desktop app and requires a logged-in user and active desktop to run. are you sure the computer you are remoting to has a logged-in user, and the desktop is available.


Your answer

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