PDA

View Full Version : Task Scheduler via COM



stanl
06-27-2008, 05:21 AM
I am posting in this section because I wrote and tested the macro code in Excel. If you have no interest whatsoever in ActiveX or expanding the range of VBA then read no further. Otherwise, something neat to play with.

From the link below you can download TaskScheduler.dll, written by Mark Pryor. This dll permits automating the Windows task scheduler through COM (as opposed to the command line SchTask.exe or the Task Wizard and sendkeys)

http://www.stonefield.com/techpap.aspx

The support files associated with the DLL are for Visual FoxPro, but easily converted to VBA (I used a typelib viewer). The code below will create a task to run notepad (assumes the dll is registered). Substitute your credentials for user and pw.


Sub TaskCreate()
'requires the freeware TaskScheduler.dll by Mark Pryor
Set oSchAgent = CreateObject("Scheduler.SchAgent")
oSchAgent.Refresh
Set oTask = oSchAgent.CreateTask("Run Notepad")
oTask.ApplicationName = "Notepad.exe"
oTask.Commandline = ""
oTask.Creator = "me"
oTask.SetAccountInformation "user", "pw"
'Create the trigger
Set oTrig = oTask.Triggers.Add
oTrig.TriggerType = 1 'ttDaily
oTrig.BeginDay = Now()
oTrig.Flags = 0
oTrig.StartTime = Now() + 12
oTrig.Update
oTask.Save
oSchAgent.Refresh
Set oSchAgent = Nothing
End Sub



Stan

Bob Phillips
06-27-2008, 05:52 AM
Interesting Stan. What typelib viewers are there out there?

stanl
06-27-2008, 12:29 PM
Interesting Stan. What typelib viewers are there out there?

Microsoft's Platinum SDK has one

http://www.jsware.net/ allows you to download jscom.dll which is a neat wrapper to write your own code to extract typelib info.

look for tlbinf32.dll on your PC, or download it - again write your own code to extract info.

I used the Wil Viewer - Stan