如何以编程方式使用C#在远程桌面中打开任务管理器

时间:2016-02-22 04:46:33

标签: c# window remote-desktop sendkeys

我使用以下代码在远程桌面连接(mstsc)中打开任务管理器。但是这段代码在我的本地机器中打开了任务管理器:

System.Diagnostics.Process p = new System.Diagnostics.Process();
Process[] rmdProcess = Process.GetProcessesByName("mstsc");

int pid = rmdProcess[0].Id;
User32.SetForegroundWindow(rmdProcess[0].MainWindowHandle.ToInt32());
IntPtr hdcSr = System.Diagnostics.Process.GetProcessById(pid).MainWindowHandle; 

SendKeys.Send("^+{ESC}");

2 个答案:

答案 0 :(得分:0)

您需要指定机器名称。另外,您需要 taskmgr 而不是 mstsc

改变这个:

Process[] rmdProcess = Process.GetProcessesByName("mstsc");

......对此:

Process[] rmdProcess = Process.GetProcessesByName("taskmgr", "<insert-machine-name-here");

更多

答案 1 :(得分:0)

我使用了以下代码并且工作正常:

//fromDate->starting date, toDate->endDate
int duration = months/unit; // 12/4 = 3
int i =1;
//printing data
System.out.println("Contract    Start date      End date")
while(fromDate.isBefore(toDate)){ 
     //get current duration, from to end
     LocalDate currentUnitEndDate = fromDate.plusMonths(unit);   
     // printing index, current time, end time for current phase.
     System.out.println(i+"    "+fromDate"      "+ currentUnitEndDate);
     //increment from date to unit no of months. 
     fromDate=fromDate.plusMonths(unit);
     i++;
}