我正在尝试使用 C# 在远程机器上创建一个进程。
我得到了所有需要的参数,并且我实际上成功地运行了该过程,但是我看不到窗口。
例如,这里我正在尝试运行记事本进程,但没有显示任何窗口,只有任务管理器中的 notepad.exe 进程。
    public void ExecuteOnRemote(string username, string password)
    {
        ConnectionOptions connOptions = new ConnectionOptions 
                                        { 
                                            Impersonation = ImpersonationLevel.Impersonate, 
                                            EnablePrivileges = true,
                                            Username = username,
                                            Password = password
                                        };
        ManagementScope scope = new ManagementScope(@"\\remoteMachineName\root\cimv2", connOptions);
        scope.Connect();
        ObjectGetOptions options = new ObjectGetOptions();
        // Getting the process class and the process startup class
        ManagementPath processClassPath = new ManagementPath("Win32_Process");
        ManagementPath processStartupClassPath = new ManagementPath("Wind32_ProcessStartup");
        ManagementClass processClass = new ManagementClass(scope, processClassPath, options);
        ManagementClass processStartupClass = new ManagementClass(scope, processStartupClassPath, options);
        // Settings the show window parameter in for a process startup class instance
        ManagementObject processStartupInstance = processStartupClass.CreateInstance();
        processStartupInstance["ShowWindow"] = 1; // A const value for showing the window normally
        // Settings the parameters for the Create method in the process class
        ManagementBaseObject inArgs = processClass.GetMethodParameters("Create");
        inArgs["CommandLine"] = "notepad.exe";
        inArgs["ProcessStartupInformation"] = processStartupInstance;
        // Invoking the method
        ManagementBaseObject returnValue = processClass.InvokeMethod("Create", inArgs, null);
    }
我的猜测是我发送的 ProcessStartupInformation 参数错误,但我仍然无法弄清楚问题出在哪里。
任何帮助,将不胜感激。
非常感谢,亚历克斯。