I am trying to build a small program that shutdown WSL and other programs that are running WSL in it like Windows Terminal.
I want the user to be able to set TRUE or FALSE in a .conf file variable depending on if the Windows Terminal wants to be closed or not by checking it with a conditional but when i add the if statement checking for the variable the program just simply doesn't work.Any ideas on where i could be making the mistake?
Here is the code:
# Gets the settings from the conig file
Foreach ($i in $(Get-Content stop.conf))
{
Set-Variable -Name $i.split("=")[0] -Value $i.split("=",2)[1]
}
# Cheks for open processes and saves it to a variable
$IDE = Get-Process $EDITOR -ErrorAction SilentlyContinue
$windowsTerminal = Get-Process $windowsterminal -ErrorAction SilentlyContinue
$linuxsys = Get-Process $DISTRO -ErrorAction SilentlyContinue
# OPTIONAL
# Checks if Windows Terminal is open and closes it
if ($WINTERMINAL -eq $true)
{
if ($windowsTerminal)
{
# Try gratefully first
$windowsTerminal.CloseMainWindow()
Sleep 5
if (!$windowsTerminal.HasExited)
{
$windowsTerminal | Stop-Process -Force
}
}
}
Just in case the .conf file looks like this:
DISTRO=ubuntu2004
EDITOR=code
WINTERMINAL=$true