Advertisement
EurenikZ

PowerShell-Script um Programm zu beenden

Dec 20th, 2024 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Programme, die beendet werden sollen
  2. $appsToClose = @(
  3.     "programm1",
  4.     "programm2",
  5.     "programm3"
  6. )
  7.  
  8. # Funktion zum sicheren Beenden von Prozessen
  9. function Close-Applications {
  10.     param (
  11.         [string[]]$processNames
  12.     )
  13.    
  14.     foreach ($processName in $processNames) {
  15.         $processes = Get-Process -Name $processName -ErrorAction SilentlyContinue
  16.        
  17.         if ($processes) {
  18.             Write-Host "Beende $processName..."
  19.             try {
  20.                 $processes | Stop-Process -Force
  21.                 Write-Host "$processName wurde erfolgreich beendet."
  22.             }
  23.             catch {
  24.                 $errorMessage = $_.Exception.Message
  25.                 Write-Warning ("Fehler beim Beenden von " + $processName + ": " + $errorMessage)
  26.             }
  27.         }
  28.         else {
  29.             Write-Host "$processName läuft nicht."
  30.         }
  31.     }
  32. }
  33.  
  34. # Benutzer informieren
  35. Write-Host "Beginne mit dem Beenden der Programme..."
  36.  
  37. # Programme beenden
  38. Close-Applications -processNames $appsToClose
  39.  
  40. Write-Host "Fertig! Alle Programme wurden beendet."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement