How to interface with Task Scheduler from VB???

  • Thread starter Thread starter Shane Story
  • Start date Start date
S

Shane Story

Have an app and would like to allow easy addition of MYAPP.EXE /F /P (for
example)

my prog with command line args, as a job to be run.

Would like to make it easier on the user to run the app. I want to have it
run automatically as specified by the user.

What is the best thing to do and what platforms would it limit me to?

Should I just try to launch MMTask.exe? And maybe make a wizard to generate
the correct command line to copy and paste into the scheduler, or should I
make my own interface and add the task?

What suggestions do you have?

I have notice the servicecontroller for interacting with a task but after
connecting I don't know how you would interface with it and haven't seen
much docs.

Thanks,

shane
 
Shane Story said:
Have an app and would like to allow easy addition of MYAPP.EXE /F /P (for
example)

my prog with command line args, as a job to be run.

Would like to make it easier on the user to run the app. I want to have it
run automatically as specified by the user.

What is the best thing to do and what platforms would it limit me to?

Should I just try to launch MMTask.exe? And maybe make a wizard to generate
the correct command line to copy and paste into the scheduler, or should I
make my own interface and add the task?

What suggestions do you have?

I have notice the servicecontroller for interacting with a task but after
connecting I don't know how you would interface with it and haven't seen
much docs.

Thanks,

shane

I've succesfully used this class to schedule tasks.
http://www.codeproject.com/csharp/TSNewLib.asp

Look in the comments at the bottom of the page for winXP and remotely
scheduling info.

HTH
Slonocode
 
Have an app and would like to allow easy addition of MYAPP.EXE /F /P (for
example)

my prog with command line args, as a job to be run.

Would like to make it easier on the user to run the app. I want to have it
run automatically as specified by the user.

What is the best thing to do and what platforms would it limit me to?

Should I just try to launch MMTask.exe? And maybe make a wizard to generate
the correct command line to copy and paste into the scheduler, or should I
make my own interface and add the task?

What suggestions do you have?

I have notice the servicecontroller for interacting with a task but after
connecting I don't know how you would interface with it and haven't seen
much docs.

Thanks,

shane

The task scheduler works on all systems with IE4 up. It exposes itself
as a set of COM interfaces. You can access this through COM interop. I
have coded all the interop definitions a while ago in C#. Here is kind
of what your in for:

using System;
using System.Runtime.InteropServices;

namespace FireAnt.Util.SchedulingAgent
{
[Guid("148BD527-A2AB-11CE-B11F-00AA00530503"),
InterfaceType(ComInterfactType.InterfactIsIUnknown)]
internal interface ITaskScheduler
{
void SetTargetComputer
([MarshalAs(UnmanagedType.LPWStr)]string pwszComputer);

[return: MarshalAs(UnmanagedType.LPWStr)]
string GetTargetComputer();

IEnumWorkItems Enum();

[return: MarshalAs(UnmanagedType.IUnknown)]
object Activate(
[MarshalAs(UnmanagedType.LPWStr)]
string pwszName,
ref Guid riid);

// rest of the method declarations...
}

// the com coclass...
[ComImport, Guid("148BD52A-A2AB-11CE-B11F-00AA00530503")]
internal class CTaskScheduler
{
}
}


Then you can use them latter...

public static void Main()
{
// get a reference to the task scheduler interface..
ITaskScheduler taskScheduler = new CTaskScheduler();

Console.WriteLine(taskScheduler.GetTargetComputer());
}

Anyway, I can give you the interop defintions if you would like...
Sorry for the C# code - but that's what I wrote this stuff in. I
started to do it in VB.NET originally - but there was a bug in the
VB.NET compiler at the time that made impossilbe...
 
Thanks Tom,

It would be great to have the definitions I would need and any advice on how
to ADD/LIST AND DELETE JOBS FROM TASK SCHEDULER

So the API you are telling me of should work the same for win98SP2, WINME,
WINXP, WIN2000, AND ABOVE? That is what I am shooting for and if necessary
win98 isn't a big deal I guess.

But my other real question is? Is it worth trying to tie into it or should
I just make a wizard that generates the commandline more easily and tell the
user to copy and pasted into a new task, by using the task scheduler? I am
trying to decide at present. This has to do with a simple backup software I
am making.

Please send the code you were speaking of. I will try to wrap in a Dll or
something. I don't know much c#, although I do know C and C++ to some
extent.

Thanks,

Shane

Tom Shelton said:
Have an app and would like to allow easy addition of MYAPP.EXE /F /P (for
example)

my prog with command line args, as a job to be run.

Would like to make it easier on the user to run the app. I want to have it
run automatically as specified by the user.

What is the best thing to do and what platforms would it limit me to?

Should I just try to launch MMTask.exe? And maybe make a wizard to generate
the correct command line to copy and paste into the scheduler, or should I
make my own interface and add the task?

What suggestions do you have?

I have notice the servicecontroller for interacting with a task but after
connecting I don't know how you would interface with it and haven't seen
much docs.

Thanks,

shane

The task scheduler works on all systems with IE4 up. It exposes itself
as a set of COM interfaces. You can access this through COM interop. I
have coded all the interop definitions a while ago in C#. Here is kind
of what your in for:

using System;
using System.Runtime.InteropServices;

namespace FireAnt.Util.SchedulingAgent
{
[Guid("148BD527-A2AB-11CE-B11F-00AA00530503"),
InterfaceType(ComInterfactType.InterfactIsIUnknown)]
internal interface ITaskScheduler
{
void SetTargetComputer
([MarshalAs(UnmanagedType.LPWStr)]string pwszComputer);

[return: MarshalAs(UnmanagedType.LPWStr)]
string GetTargetComputer();

IEnumWorkItems Enum();

[return: MarshalAs(UnmanagedType.IUnknown)]
object Activate(
[MarshalAs(UnmanagedType.LPWStr)]
string pwszName,
ref Guid riid);

// rest of the method declarations...
}

// the com coclass...
[ComImport, Guid("148BD52A-A2AB-11CE-B11F-00AA00530503")]
internal class CTaskScheduler
{
}
}


Then you can use them latter...

public static void Main()
{
// get a reference to the task scheduler interface..
ITaskScheduler taskScheduler = new CTaskScheduler();

Console.WriteLine(taskScheduler.GetTargetComputer());
}

Anyway, I can give you the interop defintions if you would like...
Sorry for the C# code - but that's what I wrote this stuff in. I
started to do it in VB.NET originally - but there was a bug in the
VB.NET compiler at the time that made impossilbe...
 
Can I use this dll in a program that I am going to resell? --the task
scheduling wouldn't be the main functino of the program of course but a
perk.

Do I need to include a copyright or what? Couldn't find information on
that.

But this does look like a great solution.

I have just downloaded it and am checking it out.

THanks,

Shane
 
Shane Story said:
Can I use this dll in a program that I am going to resell? --the task
scheduling wouldn't be the main functino of the program of course but a
perk.

Do I need to include a copyright or what? Couldn't find information on
that.

But this does look like a great solution.

I have just downloaded it and am checking it out.

THanks,

Shane


As far as I know everything on the site is freely useable.

Here is the faq page for the site.
http://www.codeproject.com/info/faq.asp


Just to be safe I'm sure you could email the author of the code.

Good Luck
Slonocode
 
Hey Tom,

Slonocode pointed me to a great library. Check it out. Works really good.

Thanks,

Shane

Shane Story said:
Thanks Tom,

It would be great to have the definitions I would need and any advice on how
to ADD/LIST AND DELETE JOBS FROM TASK SCHEDULER

So the API you are telling me of should work the same for win98SP2, WINME,
WINXP, WIN2000, AND ABOVE? That is what I am shooting for and if necessary
win98 isn't a big deal I guess.

But my other real question is? Is it worth trying to tie into it or should
I just make a wizard that generates the commandline more easily and tell the
user to copy and pasted into a new task, by using the task scheduler? I am
trying to decide at present. This has to do with a simple backup software I
am making.

Please send the code you were speaking of. I will try to wrap in a Dll or
something. I don't know much c#, although I do know C and C++ to some
extent.

Thanks,

Shane

Tom Shelton said:
have
should
I
make my own interface and add the task?

What suggestions do you have?

I have notice the servicecontroller for interacting with a task but after
connecting I don't know how you would interface with it and haven't seen
much docs.

Thanks,

shane

The task scheduler works on all systems with IE4 up. It exposes itself
as a set of COM interfaces. You can access this through COM interop. I
have coded all the interop definitions a while ago in C#. Here is kind
of what your in for:

using System;
using System.Runtime.InteropServices;

namespace FireAnt.Util.SchedulingAgent
{
[Guid("148BD527-A2AB-11CE-B11F-00AA00530503"),
InterfaceType(ComInterfactType.InterfactIsIUnknown)]
internal interface ITaskScheduler
{
void SetTargetComputer
([MarshalAs(UnmanagedType.LPWStr)]string pwszComputer);

[return: MarshalAs(UnmanagedType.LPWStr)]
string GetTargetComputer();

IEnumWorkItems Enum();

[return: MarshalAs(UnmanagedType.IUnknown)]
object Activate(
[MarshalAs(UnmanagedType.LPWStr)]
string pwszName,
ref Guid riid);

// rest of the method declarations...
}

// the com coclass...
[ComImport, Guid("148BD52A-A2AB-11CE-B11F-00AA00530503")]
internal class CTaskScheduler
{
}
}


Then you can use them latter...

public static void Main()
{
// get a reference to the task scheduler interface..
ITaskScheduler taskScheduler = new CTaskScheduler();

Console.WriteLine(taskScheduler.GetTargetComputer());
}

Anyway, I can give you the interop defintions if you would like...
Sorry for the C# code - but that's what I wrote this stuff in. I
started to do it in VB.NET originally - but there was a bug in the
VB.NET compiler at the time that made impossilbe...
 
Shane Story said:
Hey Tom,

Slonocode pointed me to a great library. Check it out. Works really
good.

Thanks,

Shane



Shane...

I'm glad you found something that works. I will check it out - but I have
long ago wrapped up these interfaces into my own library, so I'll probaby
stick with it for now :)
 
Back
Top