mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-06-30 12:41:46 +02:00
Added close-edge.ps1 and close-file-explorer.ps1
This commit is contained in:
10
Scripts/close-edge.ps1
Executable file
10
Scripts/close-edge.ps1
Executable file
@ -0,0 +1,10 @@
|
||||
#!/snap/bin/powershell
|
||||
|
||||
# Syntax: ./close-edge.ps1
|
||||
# Description: closes Microsoft Edge gracefully
|
||||
# Author: Markus Fleschutz
|
||||
# Source: github.com/fleschutz/PowerShell
|
||||
# License: CC0
|
||||
|
||||
$ExitCode = close-program.ps1 "msedge"
|
||||
exit $ExitCode
|
10
Scripts/close-file-explorer.ps1
Executable file
10
Scripts/close-file-explorer.ps1
Executable file
@ -0,0 +1,10 @@
|
||||
#!/snap/bin/powershell
|
||||
|
||||
# Syntax: ./close-file-explorer.ps1
|
||||
# Description: closes Microsoft File Explorer gracefully
|
||||
# Author: Markus Fleschutz
|
||||
# Source: github.com/fleschutz/PowerShell
|
||||
# License: CC0
|
||||
|
||||
$ExitCode = close-program.ps1 "explorer"
|
||||
exit $ExitCode
|
@ -13,16 +13,19 @@ try {
|
||||
Get-Process | Where-Object {$_.mainWindowTitle} | Format-Table Id, Name, mainWindowtitle -AutoSize
|
||||
$ProgramName = read-host "Enter program to close"
|
||||
}
|
||||
$List = Get-Process -name $ProgramName -erroraction 'silentlycontinue'
|
||||
$NumProcKilled = 0
|
||||
$List | Foreach-Object {
|
||||
|
||||
$Processes = Get-Process -name $ProgramName -erroraction 'silentlycontinue'
|
||||
foreach ($Process in $Processes) {
|
||||
$_.CloseMainWindow() | Out-Null
|
||||
$NumProcKilled++
|
||||
} | stop-process -force
|
||||
if ($NumProcKilled -eq 0) {
|
||||
}
|
||||
start-sleep -milliseconds 100
|
||||
Stop-Process -name $ProgramName -force -erroraction 'silentlycontinue'
|
||||
|
||||
$ProcessCount = $Processes.Count
|
||||
if ($ProcessCount -eq 0) {
|
||||
throw "program '$ProgramName' is not started yet"
|
||||
}
|
||||
write-output "OK - program '$ProgramName' has been closed ($NumProcKilled processes)."
|
||||
write-output "OK - program '$ProgramName' with $ProcessCount process(es) has been closed."
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
Reference in New Issue
Block a user