本文介绍了通过ASP.Net编程安排作业失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Windows计算机中创建计划作业.我正在这样做:
I''m trying to create a Scheduled job in windows machine. I am doing this:
private static uint mFnCreateJob(string Command, uint DaysOfMonth, uint DaysOfWeek, bool InteractWithDesktop, bool RunRepeatedly, string StartTime, out uint JobId) { try { ManagementBaseObject lObjInputArgs = null; ManagementScope lObjScope = new ManagementScope(@"\root\cimv2"); lObjScope.Connect(); ManagementClass lObjclassObj = new ManagementClass(lObjScope, new ManagementPath("Win32_ScheduledJob"), null); lObjInputArgs = lObjclassObj.GetMethodParameters("Create"); lObjInputArgs["Command"] = Command; lObjInputArgs["DaysOfMonth"] = DaysOfMonth; lObjInputArgs["DaysOfWeek"] = DaysOfWeek; lObjInputArgs["InteractWithDesktop"] = InteractWithDesktop; lObjInputArgs["RunRepeatedly"] = RunRepeatedly; lObjInputArgs["StartTime"] = StartTime; ManagementBaseObject outParams = lObjclassObj.InvokeMethod("Create", lObjInputArgs, null); JobId = ((uint)(outParams.Properties["JobId"].Value)); return ((uint)(outParams.Properties["ReturnValue"].Value)); } catch (Exception ex) { throw ex; } }..并且总是失败. outParams ["ReturnValue"]为2,为null outParams.Properties ["JobId"].Value…类似失败.请对此提出任何建议. 谢谢 Sreenath
..and it always fails. The outParams["ReturnValue "] is 2 and is null outParams.Properties["JobId"].Value…like fails. Any suggestions on this please. Thanks Sreenath
推荐答案您应该阅读Win32_ScheduledJob类,特别是其创建方法 [ ^ ]及其返回值"部分.您得到的返回值为2,这意味着运行代码的用户(ASPNET用户帐户或ISR_USER(?))没有创建计划作业的权限. 您的ASP.NET代码所运行的帐户需要具有对%SystemRoot%\ system32 \ Tasks文件夹的读/写权限. You should read up on the Win32_ScheduledJob class, specifically, its Create method[^] and its Return Value section. The return value you got was 2, which means the user running the code (the ASPNET user account or ISR_USER (?)) does not have permissions to create scheduled jobs. The account your ASP.NET code is running under needs to have read/write permissions to the %SystemRoot%\system32\Tasks folder.
更多推荐
通过ASP.Net编程安排作业失败
发布评论