2012-04-05 19 views
0

我需要获取本地计算机中存在的计划任务的列表。如何使用c#获取计划任务的列表?

我怎样才能做到这一点使用C#的Windows XP?

+4

什么都试过? – 2012-04-05 10:17:22

+0

看到这一点:http://stackoverflow.com/questions/6477693/c-sharp-how-to-list-scheduled-tasks-for-a-specific-user-with-the-taskschedular – nawfal 2012-04-05 10:19:37

+0

@ErikLarsson我试着nawfal说,但我缺少一些导入和'ScheduledTask'类未解决。 – 2012-04-05 10:22:35

回答

4

1替代...:

1),你可以从那里的任务是保存在文件夹中读取(伊夫只是测试它 - WIN7)

c:\Windows\System32\Tasks\ 

这是这样简单的XML文件:

<?xml version="1.0" encoding="UTF-16"?> 
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> 
    <RegistrationInfo> 
    <Date>2012-04-05T13:28:54.2106589</Date> 
    <Author>DAVIDDOM\RoyiN</Author> 
    </RegistrationInfo> 
    <Triggers> 
    <CalendarTrigger> 
     <StartBoundary>2012-04-05T13:28:43.2046589</StartBoundary> 
     <Enabled>true</Enabled> 
     <ScheduleByDay> 
     <DaysInterval>1</DaysInterval> 
     </ScheduleByDay> 
    </CalendarTrigger> 
    </Triggers> 
    <Principals> 
    <Principal id="Author"> 
     <RunLevel>LeastPrivilege</RunLevel> 
     <UserId>DAVIDDOM\RoyiN</UserId> 
     <LogonType>InteractiveToken</LogonType> 
    </Principal> 
    </Principals> 
    <Settings> 
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy> 
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries> 
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries> 
    <AllowHardTerminate>true</AllowHardTerminate> 
    <StartWhenAvailable>false</StartWhenAvailable> 
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> 
    <IdleSettings> 
     <Duration>PT10M</Duration> 
     <WaitTimeout>PT1H</WaitTimeout> 
     <StopOnIdleEnd>true</StopOnIdleEnd> 
     <RestartOnIdle>false</RestartOnIdle> 
    </IdleSettings> 
    <AllowStartOnDemand>true</AllowStartOnDemand> 
    <Enabled>true</Enabled> 
    <Hidden>false</Hidden> 
    <RunOnlyIfIdle>false</RunOnlyIfIdle> 
    <WakeToRun>false</WakeToRun> 
    <ExecutionTimeLimit>P3D</ExecutionTimeLimit> 
    <Priority>7</Priority> 
    </Settings> 
    <Actions Context="Author"> 
    <Exec> 
     <Command>C:\Windows\system32\charmap.exe</Command> 
    </Exec> 
    </Actions> 
</Task> 
+0

这是一个可能性,但nawfal的回答是去:) – 2012-04-05 10:39:00

+0

非常有用的方式! – Ryan 2016-02-04 06:53:01