sstrader
Posts: 11
Joined: Mon Dec 04, 2017 1:50 pm

Adding a scheduled task

I want to update our installer to create a user and scheduled task only if the current user is an admin. I successfully added the commands to create the user and scheduled task but I am having two issues:

1. The task is created but won't run. That user is added to the Administrators group, but the task still fails. When I (an administrator) create the task, it succeeds.
2. The user/task creation is configured to only run when the current user is an admin. However, the installer (which had not required admin privileges) now requires admin privileges no matter what.

Any suggestions or clarifications appreciated.

- Scott
Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Adding a scheduled task

Hello Scott,

I'm not sure I fully understood the behavior you are facing with nor the requirements of your setup projects. Can you please try to give us more details about that and maybe a step by step test case we can follow to replicate the issue? Also, if you could send us your AIP (project file) to support at advancedinstaller dot com so we can check its settings and configuration this will be great.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
sstrader
Posts: 11
Joined: Mon Dec 04, 2017 1:50 pm

Re: Adding a scheduled task

Daniel,

Thanks for your reply. Sorry I'm getting back to it so late. I just sent the aip, but here's some clarification.

# Under System Changes > Users and Groups, I have the installer create a new user and add them to the existing Administrators group.
# Under System Changes > Scheduled Tasks, I have the installer create a simple task that will runs a batch file installed by the installer.
# When I run the installer, it asks for admin rights and installs all components (files, user, scheduled task).
# When I try to manually run the task from the Task Scheduler it fails with "The user account does not have permission to run this task."
# When I create a similar task outside of the installer, I can run it.

Regards,
Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Adding a scheduled task

Hello Scott,

I've tested the scenario and replicated the behavior. This happens because the setup package set execute rights for the created scheduled task only for the user account you configured your setup project. Therefore any other user account will try to run the task will fail because it does not have execute rights.

To avoid this limitation you can develop your own custom action which wills set execute permissions on your created task for all admin accounts. For instnace you can proceed like this:

1. create a BAT file (e.g. taskExecuteRights.bat) with the following content:

Code: Select all

echo y|cacls "C:\Windows\System32\Tasks\<yourTaskName>" /g Administrators:F
2. add the taskExecuteRights.bat as a temporary file in "Files and Folders" page of your setup project
3. go to "Custom Actions" page and add a "Launch file" custom action with sequence scheduled as deferred after "Install Execution Stage -> Add Resources" action group like this:
  • File to launch: [&taskExecuteRights.bat]
    Command line:
    Working directory: [System64Folder]
    Hide program's window: checked
    Use 64-bit Launcher: checked
    Run under the LocalSystem account with full privileges (no impersonation): checked
4. configure the custom action condition to run only on install
5. rebuild the setup project and test the scenario again

Let us know if this helped.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
sstrader
Posts: 11
Joined: Mon Dec 04, 2017 1:50 pm

Re: Adding a scheduled task

Working now! Thanks for your help, Daniel.
Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Adding a scheduled task

You are always welcome Scott.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”