2013-07-08 69 views
1


我試圖在使用C#的遠程計算機上創建一個進程。

我得到了所有需要的參數,而且我實際上成功地運行了這個過程,但是我看不到窗口。
例如,在這裏我試圖運行一個記事本進程,但沒有窗口顯示,只有在任務管理器中的notepad.exe進程。win32_process.create不顯示窗口

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參數錯誤,但我仍然無法弄清楚問題出在哪裏。
任何幫助,將不勝感激。
非常感謝Alex。

+0

Hmya,從不低估微軟對惡意使用此功能的擔憂。顯示一個看起來像登錄對話框的窗口當然是獲取密碼的好方法。您的notepad.exe在隔離會話0的桌面上顯示其窗口。查看SysInternals的PsExec實用程序-i選項。 –

+0

非常感謝。不知道這是一個安全功能。 PsExec爲我完成了這項工作。 :-) –

回答

1
ManagementPath processStartupClassPath = new ManagementPath("Win32_ProcessStartup"); 

你在那裏犯了一個錯字。

+0

謝謝,沒有注意到,但在真正的代碼段我沒有做錯字。不管怎麼說,還是要謝謝你! :-) –