Change batch job user identity (run as)

偶尔善良 提交于 2019-12-12 17:15:57

问题


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:


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();
}


来源:https://stackoverflow.com/questions/21337580/change-batch-job-user-identity-run-as

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!