Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Running Task Scheduler
Message
 
To
14/12/2004 10:50:48
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 6 SP5
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
00969109
Message ID:
00969373
Views:
10
If Scripting is permitted, this will do it.
ssfCONTROLS = 3  && Control Panel's Schedule Tasks folder
sJobName = 'fta'  && Name of the task to run
sRunVerb = 'R&un'  && Executing command
sEndVerb = '&End Task'  && Cancelling command
shellApp = Createobject('shell.application')
oControlPanel = shellApp.Namespace(ssfCONTROLS) && Schedule Tasks folder
oST = ''
For Each folderitem In oControlPanel.items  && Loop though the items in the Control Panel items
    If folderitem.Name  = 'Scheduled Tasks'
        oST = folderitem.getfolder() && Found it
        Exit
    Endif
Next
If Vartype(oST) != 'O'
    Messagebox('Couldn't find 'TS' folder')
Endif
oJob = ''
For Each folderitem In oST.items  && Loop through the different scheduled tasks until we fiind it.
    If   Lower(folderitem.Name)  = Lower(sJobName) 
        oJob = folderitem  && Found it
        Exit
    Endif
Next
If Vartype(oJob) !='O'
    Messagebox( 'Couldn't find ' + sJobName + ' item')
Else
    bEnabled = .T.
    oRunVerb = ''
    oEndVerb = ''
    s = 'Verbs: ' + Chr(13)
    For Each Verb In oJob.verbs  && Loop through the different commands in the scheduled task until we find right one.
        s = s + Chr(13) + Verb.Name
        If Verb.Name = sRunVerb
            oRunVerb = Verb
            bEnabled = .F.
        Endif
        If Verb.Name = sEndVerb
            oEndVerb = Verb
        Endif
    Next
    If bEnabled
        oJob.InvokeVerb(oEndVerb)  && Cancel the task
    Else
        Wait Window Nowait 'executing job'
        oJob.InvokeVerb(sRunVerb)  && Run the task!
    Endif
Endif
>Is there a way to run the task scheduler from VFP code. I already have the Task Scheduler firing every 30 minutes. I need to be able to run it on the fly if necessary.
Previous
Reply
Map
View

Click here to load this message in the networking platform