请看下面。无论出于什么原因,我都无法杀死正在运行的.exe进程。随机我看到这个脚本工作,这就是为什么我认为还有其他事情发生。
我所看到的只是整个脚本在测试时起作用,但后来我宣传它只是激发了电子邮件部分。电子邮件部分很好。
这段代码是否可以保证即使挂起也会终止进程。
$process = Get-Process -Name "IVR1","IVR2","IVR3"
$IVR1path = "C:\IVR1"
$IVR2path = "C:\IVR2"
$IVR3path = "C:\IVR3"
Get-Process $process -ErrorAction SilentlyContinue
if ($process) {
Get-Process -Name $process | kill -PassThru
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 = "[email protected]"
$To = "[email protected]"
$cc = "[email protected]"
$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
}
使用以下代码。
$process = "IVR1","IVR2","IVR3" #Creates array of process names
$IVR1path = "C:\IVR1"
$IVR2path = "C:\IVR2"
$IVR3path = "C:\IVR3"
if ($process) {
Get-Process -Name $process | kill -PassThru
Start-Sleep -s 5
Start-Process "$IVR1path\IVR1.exe"
Start-Process "$IVR2path\IVR2.exe"
Start-Process "$IVR3path\IVR3.exe"
$From = "[email protected]"
$To = "[email protected]"
$cc = "[email protected]"
$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
}