Share via


A simple automation task for Windows Task Schedule

Question

Sunday, December 4, 2016 11:23 AM

Hi all,

I am trying to automate a task by using Windows Task Scheduler. What I want is to make an app run after I close Chrome.

I have some difficulties with finding how to do this in Task Scheduler and need some assistance. Is this possible to do with Task manager only?

Otherwise the only way I see how to implement such simple task is by using PowerShell commands. But I hope there is an easier way to achieve that.

All replies (5)

Tuesday, December 6, 2016 3:46 AM

Hi Jimmy,

The task scheduler can start an app based various types of triggers, including Event Log entries.

So all we need is to ensure an event is created whenever an application close, and then create a scheduled task to start whenever the event is logged.

Step one: Enable "application close"  logging

1. Start and enter secpol.msc into the Run box.
2. Navigate to Local Policies/Audit Policy.
3. Double Click Audit process tracking and enable Success.

Now, based on the article for Windows 10 below, if you close any application, if you look in Event Viewer / Security Log you will see a Process exited event 593 each time an application is exited.

Audit process tracking

https://technet.microsoft.com/en-us/itpro/windows/keep-secure/basic-audit-process-tracking

Step two: Create scheduled task based on trigger

1. Open Task Scheduler and create a new task
2. On the General Tab, give the task a name
3. On the Triggers tab, create a new trigger, and choose On an event as the trigger
4. Choose Custom, and click Edit Event Filter
5. Change the Filter settings as follows:

Now Switch to the XML tab, and enable edit query manually

You will see the following

<QueryList>
  <Query Id="0" Path="Security">
    <Select Path="Security">*[System[Provider[@Name='Microsoft-Windows-Security-Auditing'] and Task = 13313 and (band(Keywords,9007199254740992)) and (EventID=593)]]
</Select>
  </Query>
</QueryList>

Now you just need to add the application you want to cause the trigger. For example, this one uses notepad.exe as the trigger:

<QueryList>
  <Query Id="0" Path="Security">
    <Select Path="Security">
*[System[Provider[@Name='Microsoft-Windows-Security-Auditing'] and Task = 13313 and (band(Keywords,9007199254740992)) and (EventID=593)]]
and
*[EventData[Data[@Name='NewProcessName'] and (Data='C:\Windows\system32\notepad.exe')]]
</Select>
  </Query>
</QueryList>

Click Ok for this, then Ok to close the trigger dialog box.

Now choose the Action tab, and create a new action, that is Start a Program, and browse to the app you want to start along with the trigger application.

Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected].


Tuesday, December 6, 2016 12:20 PM

Thanks, Karen_Hu. Really appreciate your very useful and informative response.

My 1st concern is about secpol.msc. Because I run Windows Home on my notebook. It does not seem to include secpol within the default installation.  Is it possible to download and install it separately?


Wednesday, December 7, 2016 10:13 AM

Thanks, Karen_Hu. Really appreciate your very useful and informative response.

My 1st concern is about secpol.msc. Because I run Windows Home on my notebook. It does not seem to include secpol within the default installation.  Is it possible to download and install it separately?

Hi Jimmy,

If you are using the Windows Home Edition, the group policy is not available for you. Thereby we cannot do much thing here.

I suggest you contact script team to help you write a script as a startup option to achieve your goal.

Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected].


Wednesday, December 7, 2016 3:29 PM

That's fine. My question is addressed to everyone, including the folks who have knowledge about script-writing. Or do you suggest that I duplicate my question anywhere else?

My understanding  is that the need for   secpol.msc  could be overcome by using a couple of Registry hacks. The question is how?


Thursday, December 8, 2016 1:51 AM

Hi Jimmy,

This is the forum to discuss questions and feedback for Windows 10 general issue, better to post your question to the forum for script.

https://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?category=scripting

The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

It's not recommended you do any hack action. It may damage your Windows.

In addition, I suggest you add your Windows Edition on your post in order support engineer to give proper solution quickly.

Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected].