Jump to content

Interacting with COM object for scheduled task.


Recommended Posts

I'm trying to edit scheduled tasks through the COM object, but somehow it seems to be a little stubborn when i'm doing anything other than just reading.

$TaskRootFolder = "\myFolder"
$oTaskSchedule = ObjCreate("Schedule.Service")
$oTaskSchedule.connect()
$oRootFolder = $oTaskSchedule.GetFolder($TaskRootFolder)
If IsObj($oRootFolder) then
    $oTaskDefinition = $oRootFolder.GetTasks(0)
    $NumTasks = $oTaskDefinition.count
    ConsoleWrite($NumTasks & " tasks found in " & $TaskRootFolder & @CRLF)
    For $oTask in $oTaskDefinition
        ConsoleWrite("Task: " & $oTask.name & " enabled: " & $oTask.enabled & @LF)
        $oTask.enabled = False
    Next

Else
    ConsoleWrite("Task scheduler rootfolder not found." & @LF)
    Exit
EndIf

In the above code i connect just fine to the object, and i can read the tasks just fine. But nothing happens when i try to modify it with " $oTask.enabled = False ". I have tried every possible syntax of this i could think of but nothing works. Any info or ideas would be greatly appreciated.

Link to comment
Share on other sites

Perhaps your COM object is not in sync with the calls you are trying to read or send. Is there a newer COM object available with documentation that you can try? I have never tried using a COM object.

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

Bitten, Your code works for me on Windows 7. I have tested with $TaskRootFolder = "". I can disable and enable all tasks with your code. Are you sure you have the necessary rights to modify the tasks?

Link to comment
Share on other sites

Bitten, Your code works for me on Windows 7. I have tested with $TaskRootFolder = "". I can disable and enable all tasks with your code. Are you sure you have the necessary rights to modify the tasks?

 

Hmm, strange, it's not working on my own windows 7, however i'm part of a domain, so it may be a rights problem. I am a local administrator of my windows system though, and running it as an admin makes no difference.

Link to comment
Share on other sites

I have tested on a standalone PC. Have you tried to fill in the parameters of the Connect method?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...