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
This contains interfaces for ITaskScheduler, IEnumWorkItems, IScheduledWorkItem, ITask and ITaskTrigger. There is also some helper code at the bottom, for encapsulating the use of IEnumWorkItems. Not all methods have been tested, so be careful!

C# Definition:

using System;

using System.Collections.Generic;

using System.Runtime.InteropServices;

using System.Reflection;

namespace MSTask

{

    [Guid("a6b952f0-a4b1-11d0-997d-00aa006887ec"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IScheduledWorkItem
    {
    int CreateTrigger(                      out ushort  iTrigger,
                [MarshalAs(UnmanagedType.IUnknown)] out object  trigger);
    int DeleteTrigger(                      ushort      iTrigger);
    int GetTriggerCount(                    out ushort  iTriggerCount);
    int GetTrigger(                     ushort      iTrigger,
                [MarshalAs(UnmanagedType.IUnknown)] out object  trigger);

    int GetTriggerString(                   ushort      iTrigger,
                [MarshalAs(UnmanagedType.LPWStr)]   out string  trigger);

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

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

    [Guid("148BD524-A2AB-11CE-B11F-00AA00530503"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    interface ITask : IScheduledWorkItem
    {
    // 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);

    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);

    // 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);
    }

    [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);
    };

    public enum TASK_TRIGGER_TYPE
    {    
    TASK_TIME_TRIGGER_ONCE        = 0,
    TASK_TIME_TRIGGER_DAILY       = 1,
    TASK_TIME_TRIGGER_WEEKLY      = 2,
    TASK_TIME_TRIGGER_MONTHLYDATE     = 3,
    TASK_TIME_TRIGGER_MONTHLYDOW      = 4,
    TASK_EVENT_TRIGGER_ON_IDLE    = 5,
    TASK_EVENT_TRIGGER_AT_SYSTEMSTART = 6,
    TASK_EVENT_TRIGGER_AT_LOGON       = 7
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct TASK_TRIGGER
    {
    [MarshalAs(UnmanagedType.U2)]     public ushort          cbTriggerSize;
    [MarshalAs(UnmanagedType.U2)]     public ushort          Reserved1;
    [MarshalAs(UnmanagedType.U2)]     public ushort          wBeginYear;
    [MarshalAs(UnmanagedType.U2)]     public ushort          wBeginMonth;
    [MarshalAs(UnmanagedType.U2)]     public ushort          wBeginDay;
    [MarshalAs(UnmanagedType.U2)]     public ushort          wEndYear;
    [MarshalAs(UnmanagedType.U2)]     public ushort          wEndMonth;
    [MarshalAs(UnmanagedType.U2)]     public ushort          wEndDay;
    [MarshalAs(UnmanagedType.U2)]     public ushort          wStartHour;
    [MarshalAs(UnmanagedType.U2)]     public ushort          wStartMinute;
    [MarshalAs(UnmanagedType.U4)]     public uint        MinutesDuration;
    [MarshalAs(UnmanagedType.U4)]     public uint        MinutesInterval;
    [MarshalAs(UnmanagedType.U4)]     public uint        rgFlags;
    [MarshalAs(UnmanagedType.U4)]     public TASK_TRIGGER_TYPE   TriggerType;
    [MarshalAs(UnmanagedType.U2)]     public ushort          item1;
    [MarshalAs(UnmanagedType.U2)]     public ushort          item2;
    [MarshalAs(UnmanagedType.U2)]     public ushort          item3;
    [MarshalAs(UnmanagedType.U2)]     public ushort          item4;
    [MarshalAs(UnmanagedType.U2)]     public ushort          Reserved2;
    [MarshalAs(UnmanagedType.U2)]     public ushort          wRandomMinutesInterval;

    public ushort DaysInterval      { get { return item1; } set { item1 = value; } }
    public ushort WeeksInterval     { get { return item1; } set { item1 = value; } }
    public ushort rgfDaysOfTheWeek  { get { return item2; } set { item2 = value; } }
    public ushort wWhichWeek    { get { return item1; } set { item1 = value; } }
    public ushort rgfMonths     { get { return item3; } set { item3 = value; } }
    public uint   rgfDays       { get { return ((uint)item1 <<  0) |
                               ((uint)item2 << 16);           }
                      set { item1 = (ushort)((value >>  0) & 0xFFFF);
                        item2 = (ushort)((value >> 16) & 0xFFFF); }}
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct SYSTEMTIME
    {
    [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;
    }

    [ComImport, Guid("0000010c-0000-0000-c000-000000000046"),InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IPersist
    {
    [PreserveSig] void GetClassID(out Guid pClassID);
    }

    [ComImport, Guid("0000010b-0000-0000-C000-000000000046"),InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IPersistFile : IPersist
    {
    new void GetClassID(out Guid pClassID);
    [PreserveSig]   int IsDirty();
    [PreserveSig]   void Load(  [In, MarshalAs(UnmanagedType.LPWStr)] string pszFileName,
                    uint dwMode);
    [PreserveSig]   void Save(  [In, MarshalAs(UnmanagedType.LPWStr)] string pszFileName,
                    [In, MarshalAs(UnmanagedType.Bool)] bool fRemember);
    [PreserveSig]   void SaveCompleted([In, MarshalAs(UnmanagedType.LPWStr)] string pszFileName);
    [PreserveSig]   void GetCurFile([In, MarshalAs(UnmanagedType.LPWStr)] string ppszFileName);
    }

    public static class Scheduler
    {
    static public Guid CLSID_ITaskScheduler = new Guid("148BD52A-A2AB-11CE-B11F-00AA00530503");
    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");

    static public ITaskScheduler CreateTaskScheduler()
    {
        Type obj = Type.GetTypeFromCLSID(CLSID_ITaskScheduler, true);
        return Activator.CreateInstance(obj) as ITaskScheduler;
    }

    static public TASK_TRIGGER CreateTaskTrigger()
    {
        TASK_TRIGGER obj = new TASK_TRIGGER();
        obj.cbTriggerSize = (ushort)Marshal.SizeOf(obj);
        return obj;
    }

    static public List<string> TaskList(ITaskScheduler taskscheduler)
    {
        object obj;

        taskscheduler.Enum(out obj);

        IEnumWorkItems enumerator = obj as IEnumWorkItems;
        uint       nameCount;
        IntPtr     namePtr;
        List<string>   list       = new List<string>();

        while (enumerator.Next(1, out namePtr, out nameCount) == 0 && nameCount == 1)
        {
        IntPtr name = Marshal.ReadIntPtr(namePtr);

        list.Add(Marshal.PtrToStringUni(name));

        CoTaskMemFree(namePtr);
        CoTaskMemFree(name);
        }

        return list;
    }

    [DllImport("ole32.Dll")]
    static extern void CoTaskMemFree(IntPtr pv);
    }

}

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.

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
Find References
Show Printable Version
Revisions