Scheduled Task is Created Despite Property-based Condition - Advanced Installer Community
Cornbob
Posts: 1
Joined: Thu May 21, 2020 7:28 pm

Scheduled Task is Created Despite Property-based Condition

Hello,

I am struggling to understand why my Scheduled Task is running every installation (using AI v15.6). I have given it a condition to be created only if a property (SCHEDULED_TASK_EXISTS) = "0".
2020-05-21 11_43_48-Edit Task Properties.png
2020-05-21 11_43_48-Edit Task Properties.png (1.38 KiB) Viewed 1866 times
I have given this property a default value of 0 in the Properties section of Install Parameters.
2020-05-21 12_12_49-Edit Property.png
2020-05-21 12_12_49-Edit Property.png (3.86 KiB) Viewed 1866 times
I have a "Execute Inline Script Code" Custom Action (CheckForScheduledTask) that is in between the "Remove Resources" and "Add Resources" sequences. CheckForScheduledTask runs code from a vbscript to check whether or not the file for the scheduled task exists, and if so it will change the value of the Session.Property("SCHEDULED_TASK_EXISTS") equal to "1".

Code: Select all

Dim WindowsFolder, FSO, CustomActionData, jobfile, jobfile2

WindowsFolder = 0
Set FSO = CreateObject("Scripting.FileSystemObject")

CustomActionData = Session.Property("CustomActionData")

jobfile = FSO.BuildPath(FSO.BuildPath(FSO.GetSpecialFolder(WindowsFolder), "Tasks"), CustomActionData)
jobfile2 = FSO.BuildPath(FSO.BuildPath(FSO.GetSpecialFolder(WindowsFolder), "System32\Tasks"), CustomActionData)

if (FSO.FileExists(jobfile) Or FSO.FileExists(jobfile2)) then
  Session.Property("SCHEDULED_TASK_EXISTS") = "1"
end if
Note: This a modified version of the code I found from BillStewart on this previous topic for deleting scheduled tasks.

I am seeing in the MSI log that it does find the scheduled task and the session property's value is changed to "1". Despite this, the scheduled task is still being created. I can confirm this by checked the Date Modified timestamp for the file in C:\Windows\System32\Tasks.

What I am failing to understand is if my session property's, SCHEDULED_TASK_EXISTS, value is being changed to "1", why is my scheduled task with a condition of SCHEDULED_TASK_EXISTS = "0" created?

Any insight or suggestions would be greatly appreciated. Thank you.
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Scheduled Task is Created Despite Property-based Condition

Hello and welcome to Advanced Installer forums,

Unfortunately, without having access to the log file and the project file, some information is missing. However, based on your provided information, I was able to make some assumptions, which I would like you to correct if I am wrong.

First of all, let's start with the script. From my tests, logic wise, the script is indeed correct. It enters the "if" block correctly.

Now, what I have noticed is the fact that you use the CustomActionData property (which most likely stores the name of your scheduled task file from the %windir%\System32\Tasks folder).

Judging by this, I am assuming that your custom action is scheduled to run during the deferred stage of the installation process. What I mean by this is that your custom action has its "Execution Time" set to "When the system is being modified (deferred)" in "Custom Actions" page.

I'm assuming this because otherwise you would not need to use the "CustomActionData" property, because this property's purpose is to access another properties values during the deferred/rollback/commit stages.

If my above assumption is correct, then I'm afraid the fault line in your script is the following:

Code: Select all

Session.Property("SCHEDULED_TASK_EXISTS") = "1"
Even though the script will successfully enter the "if" block, please note that it is not possible to set properties during the deferred stage.

If my second assumption is also correct, then a solution for this problem would be to set your custom aciton's "Execution Time" to "Immediately".

Since we do this, although unnecessary, we can also dirrectly get the name of the task file through its own property, without using the CustomActionData property.

Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”