简体   繁体   English

iis用户权限来创建计划任务

[英]iis user permissions to create schedule task

my system Windows server 2012 - iis 8 - vs2015 i have created a page (aspx web forms , C#) to allow the end user to specify a report ,email and select time to receive the report by email i used TaskScheduler 2.7.2 NuGet Link to create a task schedule to do that the problem it works fine if i tested locally but when publish it return that error 我的系统Windows Server 2012-IIS 8-vs2015我创建了一个页面(aspx Web窗体,C#),以允许最终用户指定报告,发送电子邮件并选择通过电子邮件接收报告的时间,我使用TaskScheduler 2.7.2 NuGet链接创建一个任务计划来解决这个问题,如果我在本地测试,它可以正常工作,但是在发布时返回该错误

{Message: "(47,4):Task:",…} ExceptionType
"System.Runtime.InteropServices.COMException"


StackTrace "   at Microsoft.Win32.TaskScheduler.V2Interop.ITaskFolder.RegisterTaskDefinition(String Path, ITaskDefinition pDefinition, Int32 flags, Object UserId, Object password, TaskLogonType LogonType, Object sddl)
↵   at Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTaskDefinition(String path, TaskDefinition definition, TaskCreation createType, String userId, String password, TaskLogonType logonType, String sddl)↵   at Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTaskDefinition(String path, TaskDefinition definition)
↵   at slnAlabraq.Query.CreateTask(Int32 ID, String Time) in C:\Sources\slnAlabraq\slnAlabraq TFS\slnAlabraq\Query.asmx.cs:line 7655
↵   at slnAlabraq.Query.SaveRepSch(Int32 id, String Time, String Reports, String Emails) in C:\Sources\slnAlabraq\slnAlabraq TFS\slnAlabraq\Query.asmx.cs:line 7812"

the code 编码

  private string  CreateTask(int ID, string Time)
    {
        // Get the service on the local machine
        try
        {
            using (TaskService ts = new TaskService())
            {
                // Create a new task definition and assign properties
                TaskDefinition td = ts.NewTask();
                td.RegistrationInfo.Description = "Send Report By Email Schedule ID" + ID;
                td.Principal.LogonType = TaskLogonType.InteractiveToken;

                // Add a trigger that will fire the task at this time every other day
                DailyTrigger dt = (DailyTrigger)td.Triggers.Add(new DailyTrigger(1));
                dt.Repetition.Duration = TimeSpan.FromDays(5000);
                dt.Repetition.Interval = TimeSpan.FromDays(1);
                dt.StartBoundary = DateTime.Parse(Time);
                //  dt.EndBoundary = DateTime.Parse(Time).AddMinutes(20);
                // Add an action that will launch Notepad whenever the trigger fires
                td.Actions.Add(new ExecAction("C:\\Projects\\Report_Emails\\Report_Emails\\bin\\Debug\\Report_Emails.exe"));

                // Register the task in the root folder
                string taskName = "Send Report " + ID.ToString();
                //Error Here
                ts.RootFolder.RegisterTaskDefinition(taskName, td);
            }
            return "";
        }
        catch (Exception ex) { return ex.ToString(); }
    }

i think it is permission matter since it works local if it is a permission how to allow the remote user to create a task 我认为这是权限问题,因为它是本地权限(如果是权限),如何允许远程用户创建任务

thank you 谢谢

As above this will run under the website user, what that is setup to be. 如上所述,它将在网站用户下运行,即要进行设置。

Given you need to grant specific rights I'd suggest having a dedicated user for task management. 考虑到您需要授予特定权限,我建议您有一个专门的用户来进行任务管理。 You can pass in this user when creating the TaskService , ie 您可以在创建TaskService时传递该用户,即

using (TaskService ts = new TaskService(serverName, taskUser, taskDomain, taskPassword))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM