Jump to content

TaskSheduler UDF | COM error 80020009


Recommended Posts

Hey :)

I'd be glad to get some help with a TaskSheduler UDF from Water found at:

I get COM errors when trying to restore a saved .xml file with folowing code:

 

#include <TaskScheduler.au3>

Global $sFolderName = "\Microsoft\Windows\DeviceDirectoryClient"
Global $sTaskName = "HandleCommand"
Global $sBackupXML = @DesktopDir & "\HandleCommand.xml"

Global $oService = _TS_Open()
Global $vResult = _TS_TaskExportXML($oService, $sFolderName&"\"&$sTaskName, $sBackupXML)
Global $oTaskDefinition = _TS_TaskImportXML($oService, 1, $sBackupXML)
Global $oTaskObject = _TS_TaskGet($oService, $sFolderName&'\'&$sTaskName)

_TS_TaskUpdate($oService, $oTaskObject, $oTaskDefinition)
If @error Then
    MsgBox($MB_ICONERROR, "Task Scheduler UDF", "Task Scheduler UDF | _TS_TaskUpdate"&@CRLF& "@error = " & @error & ", @extended = " & @extended & @CRLF & @CRLF & _TS_ErrorText(@error))
Else
    MsgBox($MB_ICONINFORMATION, "_TS_TaskImportXML", "Task '" & $sTaskName & "' successfully updated")
EndIf
_TS_Close($oService)

 

I'd like to undestand why this code works fine for most tasks, but some produce COM Errors:

COM Error Number: 80020009 Description: ScriptLine: 1948 (Error: 80020009)
[failed] _TS_TaskUpdate Error 3304 for TargetTask:HandleCommand 
Description: _TS_TaskUpdate (3304): Error updating the Task. @extended is set to the COM error

 

Can someone help me to get rid of it pls.?

 

Link to post
Share on other sites

Please call _TS_ErrorNotify(2) at the top of your script. This way we get more detailed error information.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

Can you run your script as admin and post the result?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

@water

I added the line #RequireAdmin, but the result didn't change:

grafik.png.5c5138ee0096a9994193a0ecbed01c28.png
 

#RequireAdmin
#include <TaskScheduler.au3>
Global $sFolderName = "\Microsoft\Windows\DeviceDirectoryClient"
Global $sTaskName = "IntegrityCheck"
Global $sBackupXML = @DesktopDir & "\IntegrityCheck.xml"
Global $oService = _TS_Open()
_TS_ErrorNotify(2)
_TS_TaskExportXML($oService, $sFolderName&"\"&$sTaskName, $sBackupXML)
Global $oTaskObject = _TS_TaskGet($oService, $sFolderName&'\'&$sTaskName)
Global $oTaskDefinition = _TS_TaskImportXML($oService, 1, $sBackupXML)
_TS_TaskUpdate($oService, $oTaskObject, $oTaskDefinition)
If @error Then Exit MsgBox($MB_ICONERROR, "Task Scheduler UDF", "Task Scheduler UDF | _TS_TaskUpdate"&@CRLF& "@error = " & @error & ", @extended = " & @extended & @CRLF & @CRLF & _TS_ErrorText(@error))
MsgBox($MB_ICONINFORMATION, "_TS_TaskImportXML", "Task '" & $sTaskName & "' successfully updated")
_TS_Close($oService)

That's the xml content written with _TS_TaskExportXML() for example task "\Microsoft\Windows\DeviceDirectoryClient\IntegrityCheck"

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <SecurityDescriptor>D:P(A;;FA;;;SY)(A;;FRFX;;;BA)</SecurityDescriptor>
    <URI>\Microsoft\Windows\DeviceDirectoryClient\IntegrityCheck</URI>
  </RegistrationInfo>
  <Principals>
    <Principal id="System">
      <UserId>S-1-5-18</UserId>
    </Principal>
  </Principals>
  <Settings>
    <AllowHardTerminate>false</AllowHardTerminate>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
    <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
    <Hidden>true</Hidden>
    <MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy>
    <Priority>10</Priority>
    <RestartOnFailure>
      <Count>10</Count>
      <Interval>PT12H</Interval>
    </RestartOnFailure>
    <StartWhenAvailable>true</StartWhenAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
  </Settings>
  <Triggers>
    <TimeTrigger>
      <StartBoundary>2015-01-01T12:00:00</StartBoundary>
      <Repetition>
        <Interval>P7D</Interval>
      </Repetition>
    </TimeTrigger>
  </Triggers>
  <Actions Context="System">
    <ComHandler>
      <ClassId>{AE31B729-D5FD-401E-AF42-784074835AFE}</ClassId>
      <Data><![CDATA[-IntegrityCheck]]></Data>
    </ComHandler>
  </Actions>
</Task>

 

While trying to import this xml content via Microsoft TaskManager manually the progress fails with following message:

grafik.png.1ad74ad1fd070f2f397ec45c451cae28.png

"Task Scheduler service is not available. Task Scheduler will attemt to reconnect to it."
But the service is definitively running... checked it twice..

Here is the the list of sheduled tasks this condition matches:

\Microsoft\Windows\Device Setup\Metadata Refresh
\Microsoft\Windows\DeviceDirectoryClient\HandleCommand
\Microsoft\Windows\DeviceDirectoryClient\HandleWnsCommand
\Microsoft\Windows\DeviceDirectoryClient\IntegrityCheck
\Microsoft\Windows\DeviceDirectoryClient\LocateCommandUserSession
\Microsoft\Windows\DeviceDirectoryClient\RegisterDeviceAccountChange
\Microsoft\Windows\DeviceDirectoryClient\RegisterDeviceConnectedToNetwork
\Microsoft\Windows\DeviceDirectoryClient\RegisterDeviceLocationRightsChange
\Microsoft\Windows\DeviceDirectoryClient\RegisterDevicePeriodic1
\Microsoft\Windows\DeviceDirectoryClient\RegisterDevicePeriodic24
\Microsoft\Windows\DeviceDirectoryClient\RegisterDevicePeriodic6
\Microsoft\Windows\DeviceDirectoryClient\RegisterDevicePolicyChange
\Microsoft\Windows\DeviceDirectoryClient\RegisterDeviceScreenOnOff
\Microsoft\Windows\DeviceDirectoryClient\RegisterDeviceSettingChange
\Microsoft\Windows\DeviceDirectoryClient\RegisterUserDevice
\Microsoft\Windows\EDP\EDP App Launch Task
\Microsoft\Windows\EDP\EDP Auth Task
\Microsoft\Windows\SettingSync\BackgroundUploadTask
\Microsoft\Windows\Shell\FamilySafetyMonitorToastTask


The code works perfectly fine fine for all  other tasks..

 

Link to post
Share on other sites

I suggest to

  • stop the task before updating/make sure the task is stopped
  • check @error and @extended after each call of a _TS_* function
  • add the password to the task definition as the password does not get exported

Can you please explain why you need to update a Microsoft task? I do not see any statement modifying the task.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites
  • 2 weeks later...

@water

Hello water :) Thanx a lot for your reply. Now I had time to find a solution, but, nothing really worked. First of all:

On 6/26/2022 at 9:03 AM, water said:

Can you please explain why you need to update a Microsoft task? I do not see any statement modifying the task.

Yes I can! :)  I wanted to have a full backup of all sheduled tasks before starting to make changes, but the restore didn't work for 19 of 155 tasks. That's why I started this thread.

 

On 6/26/2022 at 9:03 AM, water said:
  • check @error and @extended after each call of a _TS_* function

I added the @error check, but indeed, _TS_TaskUpdate () and _TS_TaskRegister ()  produced the COM Errors.

Next,

On 6/26/2022 at 9:03 AM, water said:

 

  • stop the task before updating/make sure the task is stopped

All tasks were stopped (or deactivated), when _TS_TaskUpdate () was called. No changes.

Next I have manually deleted a task using the Windows TaskSheduler dialogue

\Microsoft\Windows\DeviceDirectoryClient\HandleCommand

and tried to re-register it, but the result was, that _TS_TaskRegister () failed...

Now I will try the advice from your link

On 6/26/2022 at 10:23 AM, water said:

.. that will take some time.

Have a good time!

 

Link to post
Share on other sites

Thanks for the info and good luck!

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites
  • 3 weeks later...

@water
 

So, after my holiday 😎 I tried the advices from the link you sent,

On 6/26/2022 at 10:23 AM, water said:

without success.

Then I made some changes in the exported xml files, replaced sections with configs from working exports and found out, that the issue has to do with the triggers.

Giving up.. Seems it is not possible to perform a full backup of the TaskSheduler this way.

 

Thank you for your help 👍

 

Link to post
Share on other sites

Last question:

On 6/26/2022 at 9:03 AM, water said:

add the password to the task definition as the password does not get exported

Did you add the password to the Task Definition before creating the task?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

@water

2 hours ago, water said:

Last question:

Did you add the password to the Task Definition before creating the task?

Oh, I forgot to tell about that point..
Fist of all, I did not, because some of the Tasks were created by other users (eg. SYSTEM). With the attempt to generate a full (original, unchanged) backup of the Tasks configuration that would bring me to a workaround instead of a solution.

 

I've one last question, too ;)

While playing around with _TS_TaskPropertiesSet()  ["Task|Enabled|False"] on SYSTEM tasks properties  I found out, that @error is not set, when

$oSettings.Enabled = $aTemp[2]

fails because of access denials. The ObjectError is set properly, but the line  >> If @error Then <<  doesn't work..

So I added:

If @error Then Return SetError (2005)

behind the "EndSwitch" (line 1785). Is there a better solution then mine?

 

 

Link to post
Share on other sites

Good point!
I will add the following line to the UDF: 

If @error Then Return SetError(2005, @extended, $i * -1)

This means: 
Error setting a property. @extended is set to the COM error and the Returnvalue holds the negative index of the property in error ($aProperties)

What do you think?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

Just released version 1.6.0.1 :) 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...