0

我有以下代码每 1 分钟打开记事本。但它不起作用。有人可以建议我答案吗?

using (TaskService ts = new TaskService())
{
    TaskDefinition td = ts.NewTask();
    td.RegistrationInfo.Description = "My first task scheduler";

    TimeTrigger trigger = new TimeTrigger();
    trigger.StartBoundary = DateTime.Now;
    trigger.Repetition.Interval = TimeSpan.FromMinutes(1);
    td.Triggers.Add(trigger);

    td.Actions.Add(new ExecAction(@"D:\Tasks\sample.exe", null, null));
    ts.RootFolder.RegisterTaskDefinition("TaskName", td);
}
4

1 回答 1

1

您可以使用 System.Diagnostics.Process 类打开记事本:-

Process proc = new Process();
proc.StartInfo = new ProcessStartInfo("notepad.exe");
proc.Start();

它还可以在 ProcesStartInfo 中打开特定文件:-

proc.StartInfo = new ProcessStartInfo("notepad.exe", "C://temp/log.txt");
于 2015-12-14T06:28:38.870 回答