Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Creating scheduled tasks with C#?

I'm just starting with C# and would like to copy an executable or script to a remote computer and schedule it to execute at a specific time...

Has anyone out there done this or know of an example to do this?

Duff
Tuesday, March 15, 2005

Take a look at WinAT (GUI for the AT utility). Basically Windows' version of the CRON utility in *nix. Schedule any executable or script to run at any scheduled time/interval.

It comes with the various Windows Resource Kits.

I'm sure that there are other schedulers out there as well.

Anomalous
Tuesday, March 15, 2005

Win32's NetScheduleJobAdd() ?

There's a few more that are part of the API:

NetScheduleJobAdd
NetScheduleJobDel
NetScheduleJobEnum
NetScheduleJobGetInfo

MSDN docs at: msdn.microsoft.com/library/default.asp?url=/library/en-us/netmgmt/netmgmt/schedule_functions.asp

It ain't native .NET (C#), but you should be able to call it from within .NET.

Sgt.Sausage
Tuesday, March 15, 2005

Duff,

This will do exactly what you want using the built-in scheduler in Windows:

http://www.codeproject.com/csharp/TSNewLib.asp

Arve Paalsrud
Thursday, March 17, 2005

What about a windows service with a timer?

You can use the System.Diagnostics.Process and System.Diagnostics.ProcessStartInfo to execute your cmd's with C#

I use this to execute on a server with a Delphi program that uses a commandline to execute.

Steve
Friday, March 18, 2005

Copy your executable stuff to the target computer, then run schtasks.exe to create a scheduled task in the Windows Task Scheduler.  schtasks.exe ships with WinXP, and I think Server 2003.  Although this runs fine on Win2k Server, it is coded to refuse to - there are plenty of hacked versions around which bypass this check though. We use one of these hacked versions to create scheduled tasks as part of an automated build process on Win2k Server, and it works great.

Mark B
Tuesday, March 22, 2005

*  Recent Topics

*  Fog Creek Home