NetScheduleJobAdd (netapi32)
Last changed: zippy1981 at gmail dot com-69.127.166.209

.
Summary
Adds a scheduled task to a system.

C# Signature:

    /// <summary>
    /// Adds a Windows scheduled task.
    /// </summary>
    /// <param name="Servername">
    /// The name of the machine to add the scheduled task to.
    /// NULL for localhost.
    /// </param>
    /// <param name="Buffer">A pointer to a AT_JobInfo struct.</param>
    /// <param name="JobId">An output parameter.</param>
    /// <returns>0 on success. An Error code otherwise.</returns>
    [DllImport("Netapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
    internal static extern int NetScheduleJobAdd
        (string Servername, IntPtr Buffer, out int JobId);

VB Signature:

    ''' <summary>
    ''' Adds a Windows scheduled task.
    ''' </summary>
    ''' <param name="Servername">
    ''' The name of the machine to add the scheduled task to.
    ''' NULL for localhost.
    ''' </param>
    ''' <param name="Buffer">A pointer to a AT_JobInfo struct.</param>
    ''' <param name="JobId">An output parameter.</param>
    ''' <returns>0 on success. An Error code otherwise.</returns>
    <DllImport("Netapi32.dll", CharSet := CharSet.Unicode, SetLastError := True)> _
    Friend Shared Function NetScheduleJobAdd(ByVal Servername As String, ByVal Buffer As IntPtr, ByRef JobId As Integer) As Integer
    End Function

User-Defined Types:

    /// <summary>
    /// Info for a scheduled task.
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    internal struct AT_INFO
    {
    /// <summary>
    /// Time the job is run. Expressed in milliseconds from midnight of the day the
    /// job is to be run.
    /// </summary>
    public uint JobTime;
    /// <summary>
    /// Bitmask of days of the month that the job is to be run.
    /// Bitmask is from the first to thirty first, lowest to highest bit, or 0 if the job will be run only once.
    /// </summary>
    public uint DaysOfMonth;
    /// <summary>
    /// Bitmask of days of the week that the job is to be run.
    /// Bitmask is from Monday to Sunday, from lowest to highest bit, or 0 if the job will be run only once.
    /// </summary>
    public byte DaysOfWeek;
    /// <summary>
    /// Flags to specify info about the jobs.
    /// </summary>
    public AT_JobFlags Flags;
    /// <summary>
    /// The command to run.
    /// </summary>
    [MarshalAs(UnmanagedType.LPTStr)]
    public string Command;
    }

    /// <remarks />
    [Flags]
    internal enum AT_JobFlags : byte
    {
    JOB_RUN_PERIODICALLY = 1,
    JOB_EXEC_ERROR = 2,
    JOB_RUNS_TODAY = 4,
    JOB_ADD_CURRENT_DATE = 8,
    JOB_NONINTERACTIVE = 16
    };

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

This will add a scheduled task using the older api that AT.EXE uses. Because of this, you will not be able to name the scheduled task.

Tips & Tricks:

Please add some!

Sample Code:

Please add some!

Documentation