如何指定通过Quartz.NET运行的作业运行的Windows标识?我需要安排工作以获得我们网络上服务器的免费驱动器空间。当我在不使用Quartz.NET的情况下运行代码时,它作为我通过IIS指定的Windows帐户运行。但是,当我使用相同的代码并将其移动到作业类的Execute函数时,它不会作为正确的帐户运行,而是作为基本的ASPNET帐户运行。因此,当我运行预定作业时,我在Scope.Connect()处收到ACCESS DENIED错误。
public class Scheduler
{
public static void InitializeScheduler()
{
ISchedulerFactory sf = new StdSchedulerFactory();
IScheduler sched = sf.GetScheduler();
JobDetail job = new JobDetail("job1", "group1", typeof(GetFreeSpace));
CronTrigger trigger = new CronTrigger("trigger1", "group1", "job1", "group1", "0 0 10 ? * MON");
sched.AddJob(job, true);
sched.ScheduleJob(trigger);
sched.Start();
}
}
public class GetFreeSpace : IJob
{
public void Execute(JobExecutionContext context)
{
ConnectionOptions options = new ConnectionOptions();
ManagementScope scope = new ManagementScope("Server", options);
scope.Connect();
}
}