Jump to content
Sign in to follow this  
Bitten

Interacting with COM object for scheduled task.

Recommended Posts

Bitten

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.

Share this post


Link to post
Share on other sites
Bitten

Is this not the correct forum to ask this perhaps? Or is it just too weird for anyone to know :)

Share this post


Link to post
Share on other sites
computergroove

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

Share this post


Link to post
Share on other sites
LarsJ

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?

Share this post


Link to post
Share on other sites
Bitten

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.

Share this post


Link to post
Share on other sites
LarsJ

Share this post


Link to post
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
Sign in to follow this  

×