cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
witterholt
Level 3

Import a scheduled task by using Custom Action

Hello,

From within my custom action of my Basic MSI project I try to import a scheduled task from a XML file by using the "schtasks.exe" command.

When I try to do this with a custom action of type "EXE" I constantly get a 1721 or a 1722 error.
When I try to do this with a custom action of type "VBSCRIPT" no errors occur, but the scheduled task is not created.

When I use the command in a command shell that is run as Administrator also: the scheduled task is created.

The properties that I use, DOMAIN, USERNAME, PASSWORD and INSTALLDIR, are filled correctly with their values.

I am installing on a Windows Server 2008 R2 64 bit machine.

The command that I execute has this form:
schtasks.exe /Create /TN "" /RU [DOMAIN]\[USERNAME] /RP [PASSWORD] /XML "[INSTALLDIR]"

The reason why I don't use the InstallShield functionality to create a scheduled task is that it has no options to repeat a task for a certain amount of minutes. Furthermore I need to define multiple actions in one scheduled task.

I think it has something to do with too few privileges to create the task from within InstallShield, despite the setup is executed as Administrator.

Any help is greatly appreciated!

Regards,
Chris.
Labels (1)
0 Kudos
(4) Replies
hidenori
Level 17

Is the path to schtasks.exe specified correctly? I would also make sure that the task configuration XML file is installed before your custom action is executed if the file is installed within the same installation.

Hope that helps.
0 Kudos
witterholt
Level 3

hidenori wrote:
Is the path to schtasks.exe specified correctly? I would also make sure that the task configuration XML file is installed before your custom action is executed if the file is installed within the same installation.

Hope that helps.


Hi,

Thanks for your answer. schtasks.exe is part of the Windows PATH environment variable so than it can be executed without the full path specified? But I also tried to set the working directory to System and System64.

The task configuration XML file is part of the installation and the custom action is executed after it is installed and modified by a previous custom action.

So my installation sequence regarding the scheduled task file is like this:
1.) ExecuteAction
2.) WriteConfig (custom VBSCRIPT): preset the application configuration files.
3.) CreateScheduledTask (custom VBSCRIPT): modifies the XML scheduled task file by inserting the INSTALLDIR, DOMAIN and USERNAME values.
4.) Import scheduled task (EXE): this one is failing, when I try to embed it in step three it generates no error but does not create te task.

Regards,
Chris.
0 Kudos
witterholt
Level 3

This is my custom action:


And this is the error message I get:


Regards,
Chris.
0 Kudos
witterholt
Level 3

Ok, I finally solved it by changing the "in-script execution" to "deferred execution in system context" so that the task will be created with administrator privileges.
The only problem I had after that is that the INSTALLDIR property was not available anymore in that context. I solved that by using a SetProperty that will copy the installdir value to the CustomActionData property. One of the few properties that is available when deferred execution is chosen.
0 Kudos