Quartz.NET 和 Windows 身份

发布于 2024-12-03 23:16:14 字数 997 浏览 0 评论 0原文

如何指定通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文