Add a task to task scheduler 
Author Message
 Add a task to task scheduler

Hello,

    I want to be able to have a user pick a time for a selected program to
run and then add this information into the windows task scheduler. Is there
anyone using vb.net that can point me to some documentation or some examples
of how to do this? Thanks in advance.



Tue, 15 Feb 2005 05:32:32 GMT  
 Add a task to task scheduler
Hi,

There is a set of COM interface to support Task Scheduler. 'The Task
Scheduler API'. You can find the detail reference in MSDN.

However if you want to interop from .NET, you need the tlb file. Please
follow the following steps to genrate the interop-assembly.

1. Find the mstask.idl. This file usually is under vc7\Platform\include.
2. Modify the idl file.
    Change
    struct _PSP;
    typedef struct _PSP * HPROPSHEETPAGE;
    with
    typedef void* HPROPSHEETPAGE;
    Append the code to the mstask.idl
[
 uuid(52258859-2318-4860-9C9D-BE05806016AF),
 helpstring ("Task Scheduler"),
 version (1.0)
]
library MS_TaskSched_lib
{
 importlib ("stdole32.tlb");
 [
  uuid(148BD520-A2AB-11CE-B11F-00AA00530503),
  noncreatable,
  helpstring ("Task")
 ]
 coclass CTask
 {
  [default] interface ITask;
  interface IProvideTaskPage;
  interface IPersistFile;
 };

 [
  uuid(148BD52A-A2AB-11CE-B11F-00AA00530503),
  helpstring ("Task Scheduler")
 ]
 coclass CTaskScheduler
 {
  [default] interface ITaskScheduler;
 };

Quote:
};

3. use midl to compile the idl file. Then you will get a tlb file.
4. use tlbimp to import the tlb file. (there are some warnings. If you just
want to add a new task, you can ignore it.)
5. add reference to the dll file generated by tlbimp
6. try the following code. Just demo how to create. You need reference MSDN
to complete the feature.
        Dim ts As MS_TaskSched_lib.CTaskSchedulerClass
        Dim i As MS_TaskSched_lib.IPersistFile
        Dim task As MS_TaskSched_lib.CTask
        Dim CLSID_Ctask As Guid
        Dim IID_ITask As Guid

        CLSID_Ctask = New Guid("{148BD520-A2AB-11CE-B11F-00AA00530503}")
        IID_ITask = New Guid("{148BD524-A2AB-11CE-B11F-00AA00530503}")
        ts = New MS_TaskSched_lib.CTaskSchedulerClass()

        ts.NewWorkItem("Test", CLSID_Ctask, IID_ITask, task)
        task.SetWorkingDirectory("C:\TEMP") ' Only set one property for demo
        i = task
        i.Save(Nothing, 1)

I hope this helps. If you have any questions, please reply to this post.

Best Regards,

Jun Su
Microsoft Support

---
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------

| Subject: Add a task to task scheduler
| Date: Thu, 29 Aug 2002 14:32:32 -0700
|
| Hello,
|
|     I want to be able to have a user pick a time for a selected program to
| run and then add this information into the windows task scheduler. Is
there
| anyone using vb.net that can point me to some documentation or some
examples
| of how to do this? Thanks in advance.
|
|
|
|



Fri, 18 Feb 2005 17:05:53 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How to add a task into Windows Task Scheduler from VB

2. Adding tasks to WIN95/98 Task Scheduler

3. Adding tasks to WIN95/98 Task Scheduler

4. W2k Task-Scheduler -> find hanging tasks

5. Setting Username and Passwords for a scheduled task in MS Task Scheduler

6. Creating Tasks in Task scheduler

7. How to create TASK SCHEDULER tasks

8. Adding tasks in Win Scheduler programatically

9. Adding tasks in Win Scheduler programatically

10. Adding tasks in Win Scheduler programatically

11. Add Task to Scheduler

12. Add entry to Windows Task Scheduler from VB

 

 
Powered by phpBB® Forum Software