Change batch job user identity (run as)

2019-08-03 21:50发布

I have created a couple of batch jobs and associated tasks to them, they run fine. But one problem is that they run with the account I have used to create the jobs in the first place. I would like to be a system account instead of my personal account (which could be deactivated if I ever leave this place)

I see nowhere to change this. Do I have to change it via an SQL update statement ?

Thanks.

1条回答
淡お忘
2楼-- · 2019-08-03 22:38

You can log-in as whatever service user you want and setup the batch jobs, or you can use runas(...) to do it from code easily (http://msdn.microsoft.com/en-us/library/aa893873.aspx):

server static public void Main(Args _args)
{
    RunAsPermission perm;
    UserId          runAsUser;
    SysUserInfo     userInfo;

    userInfo = SysUserInfo::find();
    runAsUser = userInfo.Id;
    perm = new RunAsPermission(runAsUser);
    perm.assert();

    runAs(runAsUser, classnum(EventJobDueDate), "runDueDateEventsForUser");

    CodeAccessPermission::revertAssert();
}
查看更多
登录 后发表回答