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

ITask (Interfaces)
 
.
Summary
Part of the Task Scheduler 1.0 Interfaces, which consists of IEnumWorkItems, ITask, ITaskScheduler, ITaskTrigger and IScheduledWorkItem. The C# definition contains some helper code. Not all methods have been tested, so be careful!
Summary
Part of the Task Scheduler 1.0 Interfaces, which consists of IEnumWorkItems, ITask, ITaskScheduler, ITaskTrigger and IScheduledWorkItem. There is some helper code below for saving a task. Not all methods have been tested, so be careful!

C# Definition:

    [Guid("148BD52B-A2AB-11CE-B11F-00AA00530503"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface ITaskTrigger
    {
    int SetTrigger( ref TASK_TRIGGER pTrigger);
    int GetTrigger( ref TASK_TRIGGER pTrigger);
    int GetTriggerString([MarshalAs(UnmanagedType.LPWStr)] out string wszTrigger);
    };
    static public Guid CLSID_ITask      = new Guid("148BD520-A2AB-11CE-B11F-00AA00530503");
    static public Guid IID_ITask        = new Guid("148BD524-A2AB-11CE-B11F-00AA00530503");
    static public Guid IID_IPersistFile     = new Guid("0000010b-0000-0000-C000-000000000046");

    public enum TASK_TRIGGER_TYPE
    {    
    TASK_TIME_TRIGGER_ONCE        = 0, // Ignore the Type field.
    TASK_TIME_TRIGGER_DAILY       = 1, // Use DAILY
    TASK_TIME_TRIGGER_WEEKLY      = 2, // Use WEEKLY
    TASK_TIME_TRIGGER_MONTHLYDATE     = 3, // Use MONTHLYDATE
    TASK_TIME_TRIGGER_MONTHLYDOW      = 4, // Use MONTHLYDOW
    TASK_EVENT_TRIGGER_ON_IDLE    = 5, // Ignore the Type field.
    TASK_EVENT_TRIGGER_AT_SYSTEMSTART = 6, // Ignore the Type field.
    TASK_EVENT_TRIGGER_AT_LOGON       = 7, // Ignore the Type field.
    }

    [Flags]
    public enum TASK_TRIGGER_FLAG
    [Guid("148BD524-A2AB-11CE-B11F-00AA00530503"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    interface ITask : IScheduledWorkItem
    {
    TASK_TRIGGER_FLAG_HAS_END_DATE     = 0x1,
    TASK_TRIGGER_FLAG_KILL_AT_DURATION_END = 0x2,
    TASK_TRIGGER_FLAG_DISABLED         = 0x4,
    }
    // Inherited from IScheduledWorkItem
    new int CreateTrigger(                      out ushort  iTrigger,
                [MarshalAs(UnmanagedType.IUnknown)] out object  trigger);
    new int DeleteTrigger(                      ushort      iTrigger);
    new int GetTriggerCount(                    out ushort  iTriggerCount);
    new int GetTrigger(                     ushort      iTrigger,
                [MarshalAs(UnmanagedType.IUnknown)] out object  trigger);

    [StructLayout(LayoutKind.Sequential)]
    public struct DAILY
    {
    public ushort DaysInterval;
    }
    new int GetTriggerString(                   ushort      iTrigger,
                [MarshalAs(UnmanagedType.LPWStr)]   out string  trigger);

    new int GetRunTimes(                    ref SYSTEMTIME pstBegin,
                                    ref SYSTEMTIME pstEnd,
                                    out ushort     count,
                                    out SYSTEMTIME rgstTaskTimes);

    new int GetNextRunTime(                     ref SYSTEMTIME pstNextRun);
    new int SetIdleWait(                    ushort     wIdleMinutes,
                                    ushort     wDeadlineMinutes);
    new int GetIdleWait(                    out ushort     wIdleMinutes,
                                    out ushort     wDeadlineMinutes);
    new int Run();
    new int Terminate( );
    new int EditWorkItem(                       IntPtr     hParent,
                                    uint       dwReserved);
    new int GetMostRecentRunTime(                   out SYSTEMTIME pstLastRun);
    new int GetStatus(                      out uint       hrStatus);
    new int GetExitCode(                    out uint       dwExitCode);
    new int SetComment(       [MarshalAs(UnmanagedType.LPWStr)] string     Comment);
    new int GetComment(       [MarshalAs(UnmanagedType.LPWStr)] out string     Comment);
    new int SetCreator(       [MarshalAs(UnmanagedType.LPWStr)] string     Creator);
    new int GetCreator(       [MarshalAs(UnmanagedType.LPWStr)] out string     Creator);
    new int SetWorkItemData( ushort cbData,Byte[] rgbData);
    new int GetWorkItemData(  out ushort cbData,
                  out Byte[] rgbData);
    new int SetErrorRetryCount( ushort wRetryCount);
    new int GetErrorRetryCount( out ushort wRetryCount);
    new int SetErrorRetryInterval( ushort wRetryInterval);
    new int GetErrorRetryInterval( out ushort wRetryInterval);
    new int SetFlags( uint dwFlags);
    new int GetFlags( out uint dwFlags);
    new int SetAccountInformation(  [MarshalAs(UnmanagedType.LPWStr)] string AccountName,
                    [MarshalAs(UnmanagedType.LPWStr)] string PassUInt16);
    new int GetAccountInformation(  [MarshalAs(UnmanagedType.LPWStr)] out string AccountName);

    [StructLayout(LayoutKind.Sequential)]
    public struct WEEKLY
    {
    public ushort WeeksInterval;
    public ushort rgfDaysOfTheWeek;
    // Methods specific to ITask
    int SetApplicationName([MarshalAs(UnmanagedType.LPWStr)]   string ApplicationName);
    int GetApplicationName([MarshalAs(UnmanagedType.LPWStr)] out string ApplicationName);
    int SetParameters([MarshalAs(UnmanagedType.LPWStr)]   string Parameters);
    int GetParameters([MarshalAs(UnmanagedType.LPWStr)] out string Parameters);
    int SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)]   string WorkingDirectory);
    int GetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] out string WorkingDirectory);
    int SetPriority(uint Priority);
    int GetPriority(out uint Priority);
    int SetTaskFlags(uint Flags);
    int GetTaskFlags(out uint Flags);
    int SetMaxRunTime(uint MaxRunTimeMS);
    int GetMaxRunTime(out uint MaxRunTimeMS);
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct MONTHLYDATE
    public struct SYSTEMTIME
    {
    public uint rgfDays;
    public ushort rgfMonths;
    [MarshalAs(UnmanagedType.U2)] short Year;
    [MarshalAs(UnmanagedType.U2)] short Month;
    [MarshalAs(UnmanagedType.U2)] short DayOfWeek;
    [MarshalAs(UnmanagedType.U2)] short Day;
    [MarshalAs(UnmanagedType.U2)] short Hour;
    [MarshalAs(UnmanagedType.U2)] short Minute;
    [MarshalAs(UnmanagedType.U2)] short Second;
    [MarshalAs(UnmanagedType.U2)] short Milliseconds;
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct MONTHLYDOW
    {
    public ushort wWhichWeek;
    public ushort rgfDaysOfTheWeek;
    public ushort rgfMonths;
    }

C# Helper Code

    using System;
    using System.Runtime.InteropServices;

    [StructLayout(LayoutKind.Explicit)]
    public struct TRIGGER_TYPE_UNION
    static public int SaveTask(object task)
    {
    [FieldOffset(0)] public DAILY       Daily;
    [FieldOffset(0)] public WEEKLY      Weekly;
    [FieldOffset(0)] public MONTHLYDATE MonthlyDate;
    [FieldOffset(0)] public MONTHLYDOW  MonthlyDOW;
    }
    IntPtr  fileObj;
    int     hr = 0;

    [StructLayout(LayoutKind.Sequential)]
    public struct TASK_TRIGGER
    {
    public ushort          cbTriggerSize;
    public ushort          Reserved1;
    public ushort          wBeginYear;
    public ushort          wBeginMonth;
    public ushort          wBeginDay;
    public ushort          wEndYear;
    public ushort          wEndMonth;
    public ushort          wEndDay;
    public ushort          wStartHour;
    public ushort          wStartMinute;
    public uint        MinutesDuration;
    public uint        MinutesInterval;
    public TASK_TRIGGER_FLAG   rgFlags;
    public TASK_TRIGGER_TYPE   TriggerType;
    public TRIGGER_TYPE_UNION  Type;
    public ushort          Reserved2;
    public ushort          wRandomMinutesInterval;
    hr = Marshal.QueryInterface(Marshal.GetIUnknownForObject(task), ref IID_IPersistFile, out fileObj);
    if (hr != 0)
        return hr;

    static public TASK_TRIGGER CreateInstance()
    {
        TASK_TRIGGER obj = new TASK_TRIGGER();
        obj.cbTriggerSize = (ushort)Marshal.SizeOf(obj);
        return obj;
    }
    }
    IPersistFile file = Marshal.GetObjectForIUnknown(fileObj) as IPersistFile;

VB Definition:

<ComImport> _
<Guid("TODO")> _
'TODO: Insert <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _ if this doesn't derive from IDispatch
Interface ITaskTrigger
   TODO
End Interface

User-Defined Types:

None.

    file.Save(null, true);
    return hr;
    }

Notes:

VB Definition:

<ComImport> _
<Guid("TODO")> _
'TODO: Insert <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _ if this doesn't derive from IDispatch
Interface ITask
   TODO
End Interface

User-Defined Types:

None.

Documentation

Notes:

None.

Documentation
ITask on MSDN

Please edit this page!

Do you have...

  • helpful tips?
  • corrections to the existing content?
  • alternate definitions?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing any supporting types needed.

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