0

I have the below script but it seems it wont kill the child processes. How do i kill child processes?

When it runs, it looks fine but then there are dialog boxes left over and then when i check task manager the original processes are still running. Which makes me think if the script ran properly. The other weird part to this is that naturally I would see these processes (.exe programs) running active on the task bar but after the script runs they look like they aren't running. But again, I check task manager and sure enough, they are still running.

$ErrorActionPreference = "SilentlyContinue"
Stop-Transcript | Out-Null
$ErrorActionPreference = "Continue"
Start-Transcript -Path C:\Scripts\Errors\errors.log -Append
$process = Get-Process -Name "IVR1","IVR2","IVR3"
$IVR1path = "C:\IVR1"
$IVR2path = "C:\IVR2"
$IVR3path = "C:\IVR3"
if ($process) {
    $Process | Stop-Process -Force
    Start-Sleep -s 5
    cd $IVR1path
    Start-Process ".\IVR1.exe"
    cd IVR2path
    Start-Process ".\IVR2.exe"
    cd IVR3path
    Start-Process ".\IVR3.exe"
    cd ..
    cd ..
    $From = "IVR1@example.com.au"
    $To = "myemail@example.com.au"
    $cc = "myemail@example.com.au"
    $Subject = "**TEST** - IVR1 has been recovered"
    $Body = "The IVR has been successfully recovered"
    $SMTPServer = "mail.example.com.au"
    Send-MailMessage -From $From -to $To -cc $cc -Subject $Subject -Body $Body -SmtpServer $SMTPServer
    Stop-Transcript
}

Would anyone have any suggestions? Could it be due to child processes not being killed or the original process being hung?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • 1
    what is the difference between your current question here and the previous one from 8 hours previous? this one >> Can't kill off an .exe file using Powershell V4.0 - Stack Overflow — https://stackoverflow.com/questions/54699835/cant-kill-off-an-exe-file-using-powershell-v4-0 – Lee_Dailey Feb 15 '19 at 06:27
  • The difference being is that the last question was related to only killing the .exe processes but when I do that you mentioned you wouldn't work so thought maybe it's related to a different scenario hence the new question above. How do I kill a child process? Can you please help – rohan groombridge Feb 15 '19 at 07:24
  • my last comment in that thread linked to a different way to terminate a process - by using WMI calls. did you ever try that? – Lee_Dailey Feb 15 '19 at 07:31
  • There are lot of broken pieces which wish to connect address but primarily, where is this `Get-Process -name $processname | kill -PassThru` – Ranadip Dutta Feb 15 '19 at 07:43
  • 1
    Please stop formatting code as snippets when the code is not a [runnable snippet](https://stackoverflow.blog/2014/09/16/introducing-runnable-javascript-css-and-html-code-snippets/). For code formatting use the `{}` icon in the toolbar. – Ansgar Wiechers Feb 15 '19 at 09:01

1 Answers1

0

I think that you've misused tools you have to achieve the goal. Use https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-process?view=powershell-4.0 and functions listed at the end of page ( all about process lifecycle ). Side note: add more verbosity ( write-output variable values) to what your script does so you will know what is happening ( or use the debugger, because I`m not sure if most of code you pasted is even executed ).