PDA

View Full Version : Import a scheduled task by using Custom Action



witterholt
08-13-2014, 02:23 PM
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 "<Task name>" /RU [DOMAIN]\[USERNAME] /RP [PASSWORD] /XML "[I]<XML File Name>"

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.

hidenori
08-13-2014, 05:32 PM
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.

witterholt
08-14-2014, 01:23 AM
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.

witterholt
08-18-2014, 01:10 AM
This is my custom action:
10579

And this is the error message I get:
10578

Regards,
Chris.

witterholt
10-07-2014, 06:24 AM
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.