You can gracefully terminate a program normally by:
Get-Process "*notepad*" | Foreach-Object {$_.CloseMainWindow()}
I'm using a DSC configuration with Package or a cChoco resource to install a package. I'd like to warn the user the program is updating (msg * "Closing in 5 minutes" for example) and then attempt to close the program gracefully.
I'm unable to get this to work in a Chocolatey package (chocolateyinstall.ps1) or in a Desired State Configuration Script. I've also tried it running as a task scheduled script with no luck. I'm guessing because the process is running in a different context that DSC/Task Scheduler is running in.
I'm able to kill the process with Get-Process "*notepad*" | Stop-Process
, but that just kills the process.
Is there any way I can do this? I'm guessing this would be the same as calling CloseMainWindow()
on a process with a login script.