-
Notifications
You must be signed in to change notification settings - Fork 0
/
shutdown.ps1
71 lines (55 loc) · 1.93 KB
/
shutdown.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Developed by: https://github.com/Flamiing
# Poweshell Script to turn off WSL and all the programs using it
# IMPORTANT:
# This script will close your desired IDE and Linux Distribution
# It will close Windows Terminal if set to 'true' in the config file
# For more info please visit: https://github.com/Flamiing/SmartStop
try
{
# Gets the settings from the conig file
Foreach ($i in $(Get-Content ../../../etc/"Smart Stop"/settings.conf))
{
Set-Variable -Name $i.split("=")[0] -Value $i.split("=",2)[1]
}
# Checks for open processes and saves it to a variable
$IDE = Get-Process $EDITOR -ErrorAction SilentlyContinue
$windowsTerminal = Get-Process windowsterminal -ErrorAction SilentlyContinue
$openConsole = Get-Process openconsole -ErrorAction SilentlyContinue
# OPTIONAL:
# Checks if Windows Terminal is open and closes it
if ([bool]::Parse($WINTERMINAL))
{
$windowsTerminal | Stop-Process -Force
$openConsole | Stop-Process -Force
}
# Removes variables after use
Remove-Variable windowsTerminal
Remove-Variable openConsole
Remove-Variable WINTERMINAL
# Checks if IDE is open and closes it
if ($IDE)
{
$IDE | Stop-Process -Force
}
# Removes variables after use
Remove-Variable IDE
Remove-Variable EDITOR
# Stops the distro
wsl --terminate $DISTRO
# Removes variable after use
Remove-Variable DISTRO
# After all the apps using WSL are closed it turns it off and exits
wsl --shutdown
}
catch
{
# Goes to the Documents path
Set-Location ([Environment]::GetFolderPath("MyDocuments"))
# If Smart Stop folder does not exist is created
if (-not (Test-Path 'Smart Stop'))
{
New-Item -Path 'Smart Stop' -ItemType Directory
}
# Writes errors into a log file
$Error > 'Smart Stop/error.log'
}