Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

NetScheduleJobAdd (netapi32)
 
.
Summary
Adds a scheduled task to a system.

C# Signature:

    /// <summary>
    /// Adds a Windows scheduled task.
    /// Adds a windows schedukled 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.
    ''' Adds a windows schedukled 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.
    /// Bitmast of days of the month that the job is to be run.
    /// Bitmask is from the first to thirty first, lowest to highest bit.
    /// </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.
    /// Bitmast of days of the week that the job is to be run.
    /// Bitmask is from Monday to Friday, from lowest to highest bit.
    /// </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

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions