我需要將在某個主機上運行的所有計劃任務列表轉換爲C#中的列表或數組。如何通過Process.Start()以列表或數組的形式讀取從命令運行的標準輸出
查詢
schtasks /query /S CHESTNUT105B /FO List
返回像這樣的列表:
HostName: CHESTNUT105B
TaskName: Calculator
Next Run Time: 12:00:00, 10/28/2010
Status: Running
HostName: CHESTNUT105B
TaskName: GoogleUpdateTaskMachineCore
Next Run Time: At logon time
Status:
HostName: CHESTNUT105B
TaskName: GoogleUpdateTaskMachineCore
Next Run Time: 13:02:00, 10/28/2010
我有以下的代碼來執行我上面指定的命令:
static void Main(string[] args)
{
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "SCHTASKS.exe";
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
string MachineName = "CHESTNUT105b";
string ScheduledTaskName = "Calculator";
string activeDirectoryDomainName = "xxx";
string userName = "xxx";
string password = "xxxxx";
p.StartInfo.Arguments = String.Format("/Query /S {0} /FO LIST", MachineName);
p.Start();
}
我怎麼能讀列表生成到C#中的列表?
這個問題的
我確信有更好的方法來檢索列表 - 通過WMI類,但我不知道該名稱空間足以提供答案。 – Oded 2010-10-27 19:03:12