mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-25 17:33:17 +01:00
Added close-chrome.ps1 and close-thunderbird.ps1
This commit is contained in:
parent
519fbbb709
commit
4946b67d1f
@ -11,7 +11,9 @@ The following PowerShell scripts can be found in the [Scripts/](Scripts/) subfol
|
||||
* [check-mac-address.ps1](Scripts/check-mac-address.ps1) - checks the given MAC address for validity
|
||||
* [check-xml-file.ps1](Scripts/check-xml-file.ps1) - checks the given XML file for validity
|
||||
* [clone-repos.ps1](Scripts/clone-repos.ps1) - clones well-known Git repositories
|
||||
* [close-chrome.ps1](Scripts/close-chrome.ps1) - closes Google Chrome gracefully
|
||||
* [close-program.ps1](Scripts/close-program.ps1) - closes the given program gracefully
|
||||
* [close-thunderbird.ps1](Scripts/close-thunderbird.ps1) - closes Mozilla Thunderbird gracefully
|
||||
* [close-windows-terminal.ps1](Scripts/close-windows-terminal.ps1) - closes Windows Terminal gracefully
|
||||
* [configure-git.ps1](Scripts/configure-git.ps1) - sets up the Git configuration
|
||||
* [csv-to-text.ps1](Scripts/csv-to-text.ps1) - converts the given CSV file into a text list
|
||||
|
10
Scripts/close-chrome.ps1
Executable file
10
Scripts/close-chrome.ps1
Executable file
@ -0,0 +1,10 @@
|
||||
#!/snap/bin/powershell
|
||||
|
||||
# Syntax: ./close-chrome.ps1
|
||||
# Description: closes Google Chrome gracefully
|
||||
# Author: Markus Fleschutz
|
||||
# Source: github.com/fleschutz/PowerShell
|
||||
# License: CC0
|
||||
|
||||
$ExitCode = close-program.ps1 "chrome"
|
||||
exit $ExitCode
|
@ -14,15 +14,16 @@ try {
|
||||
$ProgramName = read-host "Enter program to close"
|
||||
}
|
||||
$List = Get-Process -name $ProgramName -erroraction 'silentlycontinue'
|
||||
$NumProc = 0
|
||||
$List | Foreach-Object { $NumProc++; $_.CloseMainWindow() | Out-Null } | stop-process -force
|
||||
if ($NumProc -eq 0) {
|
||||
write-error "ERROR: No processes for program '$ProgramName' found"
|
||||
exit 1
|
||||
} else {
|
||||
write-output "Done - $NumProc processes stopped."
|
||||
exit 0
|
||||
$NumProcKilled = 0
|
||||
$List | Foreach-Object {
|
||||
$_.CloseMainWindow() | Out-Null
|
||||
$NumProcKilled++
|
||||
} | stop-process -force
|
||||
if ($NumProcKilled -eq 0) {
|
||||
throw "program '$ProgramName' is not started yet"
|
||||
}
|
||||
write-output "OK - program '$ProgramName' has been closed ($NumProcKilled processes)."
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
|
10
Scripts/close-thunderbird.ps1
Executable file
10
Scripts/close-thunderbird.ps1
Executable file
@ -0,0 +1,10 @@
|
||||
#!/snap/bin/powershell
|
||||
|
||||
# Syntax: ./close-thunderbird.ps1
|
||||
# Description: closes Mozilla Thunderbird gracefully
|
||||
# Author: Markus Fleschutz
|
||||
# Source: github.com/fleschutz/PowerShell
|
||||
# License: CC0
|
||||
|
||||
$ExitCode = close-program.ps1 "thunderbird"
|
||||
exit $ExitCode
|
@ -1,15 +1,10 @@
|
||||
#!/snap/bin/powershell
|
||||
|
||||
# Syntax: ./close-windows-terminal.ps1
|
||||
# Description: closes the Windows Terminal program gracefully
|
||||
# Description: closes Windows Terminal gracefully
|
||||
# Author: Markus Fleschutz
|
||||
# Source: github.com/fleschutz/PowerShell
|
||||
# License: CC0
|
||||
|
||||
close-program.ps1 "WindowsTerminal"
|
||||
#try {
|
||||
# exit 0
|
||||
#} catch {
|
||||
# write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
# exit 1
|
||||
#}
|
||||
$ExitCode = close-program.ps1 "WindowsTerminal"
|
||||
exit $ExitCode
|
||||
|
Loading…
Reference in New Issue
Block a user