I’m trying to create a powershell script that will create a scheduled task that will trigger on event, that event is whenever a specific exe file has closed, in my case it’s Update.exe which is a part of discord updater, so whenever discord has been updated (after update.exe has been closed) the scheduled task will run.
I don’t know which values I need to give task scheduler (even without powershell) in order to make it work, of course I tried google but all the results I am getting are related to “how to schedule to run a exe file”, which is not what I want.
In a way - this is off-topic from powershell, but since I eventually would like to use those values in powershell to create a scheduled task, I guess it’s not entirely off-topic (and also google did not help)
I think the main issue is that Task Scheduler can’t detect when a given executable has stopped running or even when it’s started for that matter.
Now if Discord’s update.exe happens to log something in Event Viewer then you’ve got a chance. You can use the XML filter options and then there will be a path forward for creating this with PowerShell, but in the meantime, you need some kind of log entry to look for.
What’s the actual purpose of this requirement? What should the script do when the discord updater ran? Does it really have to be immediately afterwards or can there be some delay?
@Olaf
The actual purpose of this requirement is installing BetterDiscord whenever Discord finished updating. The script to install BetterDiscord has already been completed.
I created a scheduled task that will run every time a user logon in order to install BetterDiscord, but that’s not ideal, yes, it works, but it could be better, that’s why I’m searching for ways to make it wait for whenever Discord finished updating.
It doesn’t have to be immediately afterwards, there can be some delay, but I think that immediately afterwards will work best to minimize waiting time, there’s not much reason to have delay.
I tested it by opening Discord’s update.exe and remembering the timestamp I did it on, then I searched for anything on the Event Viewer that relates to that timestamp but haven’t found anything, but I think it’s my lack of knowledge in this regard, I could have skipped something and missed it.
There are advanced auditing settings available that can track process creation and exit, but this update process may run more than you think to simply check for updates. A different solution might be to just run the task on a timer, track the version of discord and if it changes then run your other script
Interesting…
So you’re saying there are 2 ways to go about it, the first is track process creation and exit, the second is timing it.
The second approach which is timing seems wrong, I’ll explain why, let’s assume I’m in a Discord call all of the sudden Discord closes (to install BetterDiscord), it’s not something I want to happen, it seems very intrusive and annoying.
The first approach seems more logical, once Discord’s update.exe closed then the script will run (the script that installs BetterDiscord), there’s no need to even track Discord version in this case because the (already completed) script that installs BetterDiscord already does that.
Can you elaborate on this first approach and how it can be done? I would like to explore that option.
<$.02>
But, it can detect a specific Event ID from a Specific Log which could be tied to the Discord Task. Under Triggers for the task, trigger on an Event and then from the custom settings for the trigger, you can define a New Event Trigger that looks for ID 102 on the Discord task from the Microsoft-Windows-TaskScheduler/Operational log. You can even get very granular using XML.
</$.02>
sorry if i wasn’t clear in my reply but this is essentially what I was driving at. I’ve done something similar but there was a very specific Event I could trigger off of.
I’ll have to take a look at Discord and see if there’s anything in Event Viewer, but from my cursory searching online, it doesn’t look good.
I opened Event Viewer > Applications and Services Logs > Microsoft > Windows > TaskScheduler > Operational.
There’s nothing here, not a single thing, it’s empty.
By the way, I don’t think Discord has a updater scheduled task, it only updates when you launch the program itself (which is update.exe), so I’m not surprised I haven’t found anything in the Event Viewer.
I just fired up Discord and also found nothing. Some googling revealed that some people were finding correlations between some Powershell logs and Discord running but even looking in Event Viewer > Applications and Services > Windows PowerShell was fruitless. There are events happening in there around when discord starts but there’s nothing in there that says “Discord” so you wouldn’t have anything to trigger on.
I even manually triggered an update in Discord and nothing relevant got logged.
It looks like your only option might be to just do a time based event and build in a bunch of logic to check and make sure Discord’s not actively being used.
Are you sure the log is enable? Select Properties on the log to validate.
If there are not entries here, As was mentioned above, you could set your audit policy to audit Process Termination, then trigger the task on that event with filtering for Discord. Could get ugly though.
Sorry, never had or use Discord so I am out of line here my apology. Bowing out …