示例#1
0
    /// <summary>
    /// Deletes task if exists.
    /// This process must be admin.
    /// </summary>
    /// <param name="taskFolder">See <see cref="RunTask"/>.</param>
    /// <param name="taskName">See <see cref="RunTask"/>.</param>
    /// <exception cref="Exception">Failed.</exception>
    public static void DeleteTask(string taskFolder, string taskName)
    {
        var ts = new Api.TaskScheduler() as Api.ITaskService;

        ts.Connect();
        try { ts.GetFolder(taskFolder).DeleteTask(taskName, 0); } catch (FileNotFoundException) { }
    }
示例#2
0
    /// <summary>
    /// Returns true if the task exists.
    /// </summary>
    /// <param name="taskFolder">See <see cref="RunTask"/>.</param>
    /// <param name="taskName">See <see cref="RunTask"/>.</param>
    /// <exception cref="Exception">Failed.</exception>
    public static bool TaskExists(string taskFolder, string taskName)
    {
        var ts = new Api.TaskScheduler() as Api.ITaskService;

        ts.Connect();
        try { ts.GetFolder(taskFolder).GetTask(taskName); }
        catch (FileNotFoundException) { return(false); }
        return(true);
    }
示例#3
0
    /// <summary>
    /// Runs task. Does not wait.
    /// Returns process id.
    /// </summary>
    /// <param name="taskFolder">Can be like <c>@"\Folder"</c> or <c>@"\A\B"</c> or <c>"Folder"</c> or <c>@"\"</c> or <c>""</c> or null.</param>
    /// <param name="taskName">Can be like <c>"Name"</c> or <c>@"\Folder\Name"</c> or <c>@"Folder\Name"</c>.</param>
    /// <param name="joinArgs">Join args into single arg for $(Arg0).</param>
    /// <param name="args">Replacement values for substrings $(Arg0), $(Arg1), ..., $(Arg32) in 'create task' args. See <msdn>IRegisteredTask.Run</msdn>.</param>
    /// <exception cref="Exception">Failed. Probably the task does not exist.</exception>
    public static int RunTask(string taskFolder, string taskName, bool joinArgs, params string[] args)
    {
        object a; if (args.NE_())

        {
            a = null;
        }
        else if (joinArgs)
        {
            a = StringUtil.CommandLineFromArray(args);
        }
        else
        {
            a = args;
        }
        var ts = new Api.TaskScheduler() as Api.ITaskService;

        ts.Connect();
        var rt = ts.GetFolder(taskFolder).GetTask(taskName).Run(a);

        rt.get_EnginePID(out int pid);
        return(pid);
    }