简体   繁体   English

win32_process.create 不显示窗口

[英]win32_process.create does not show window


I'm trying to create a process on a remote machine using C#.我正在尝试使用 C# 在远程机器上创建一个进程。

I get all the needed parameters, and I actually succeed in running the process, but I can't see the window.我得到了所有需要的参数,我实际上成功地运行了这个过程,但是我看不到窗口。
For example, here I'm trying to run a notepad process, but no window is showing up, only a notepad.exe process in the Task Manager.例如,在这里我试图运行一个记事本进程,但没有显示窗口,只有任务管理器中的 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);
    }

My guess is that I'm sending the ProcessStartupInformation parameter wrong, but I still can't figure out where is the problem.我的猜测是我发送的 ProcessStartupInformation 参数错误,但我仍然无法弄清楚问题出在哪里。
Any help would be appreciated.任何帮助,将不胜感激。
Thanks a lot, Alex.非常感谢,亚历克斯。

Microsoft prohibits this explicitly . Microsoft明确禁止这样做。

http://msdn.microsoft.com/en-us/library/aa389388(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/aa389388(v=vs.85).aspx

For security reasons the Win32_Process.Create method cannot be used to start an interactive process remotely.出于安全原因,Win32_Process.Create 方法不能用于远程启动交互式进程。

ManagementPath processStartupClassPath = new ManagementPath("Win32_ProcessStartup");

你在那里打错字了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM