/// <summary>
/// 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);
''' <summary>
''' 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
/// <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>
/// 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>
/// 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 />
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
};
Do you know one? Please contribute it!
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.
Please add some!
Please add some!