Quartz.NET 和 Windows 身份
如何指定通过 Quartz.NET 调度的作业运行时的 Windows 身份?我需要安排作业以获得网络上服务器的可用驱动器空间。当我在不使用 Quartz.NET 的情况下运行代码时,它作为我通过 IIS 指定的 Windows 帐户运行。但是,当我采用相同的代码并将其移动到作业类的执行函数时,它不会作为正确的帐户运行,而是作为基本 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();
}
}
How do you specify the Windows Identity that jobs scheduled through Quartz.NET run as? I need to schedule jobs to get the free drive space of servers on our network. When I run the code without using Quartz.NET it runs as the Windows Account that I have specified through IIS. However, when I take that same code and move it to the Execute function of a job class it does NOT run as the proper account but rather as the basic ASPNET account. So, when I run the scheduled jobs I am getting an ACCESS DENIED error at Scope.Connect().
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();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论