Consulting

Results 1 to 3 of 3

Thread: Task Scheduler via COM

  1. #1
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location

    Task Scheduler via COM

    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.

    [vba]
    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

    [/vba]

    Stan

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Interesting Stan. What typelib viewers are there out there?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by xld
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •