Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) | Reguli | Inregistrare | Login

POZE MRRRR'S FORUM (VIEW ONLY)

Nu sunteti logat.
Nou pe simpatie:
Alexandrina1 pe Simpatie.ro
Femeie
22 ani
Arges
cauta Barbat
22 - 46 ani
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides / [WINDOWS] Force Close Programs with Powershell File and Batch File Moderat de TRaP, TonyTzu
Autor
Mesaj Pagini: 1
Mrrrr
AdMiN

Inregistrat: acum 17 ani
Postari: 2186
If I try to shut down my PC (Windows 10) with several programs open (Steam, Epic Games, Internet Download Manager, ShareX etc.) it will bring the screen with the list and ask me if I want to force shut down.

Since I don't want that, I made the following Powershell script that runs through a batch file, that colors text depending on action taken (more colors:). You can use -ForegroundColor for text color, and -BackgroundColor for highlight color.

Save this with the extension .ps1



# example: Powershell -command "Write-Host 'Outlook process was found and stopped' -ForegroundColor Red -BackgroundColor White"

if((get-process "Outlook" -ea SilentlyContinue) -eq $Null){
      Powershell -command "Write-Host 'Outlook not running, nothing to stop, moving on...' -ForegroundColor Green"
}

else{
    Stop-Process -processname "Outlook"
    Powershell -command "Write-Host 'Outlook process was found and stopped' -ForegroundColor Red"
    Start-Sleep -s 1
}

if((get-process "steam" -ea SilentlyContinue) -eq $Null){
        Powershell -command "Write-Host 'Steam not running, nothing to stop, moving on...' -ForegroundColor Green"
}

else{
    Stop-Process -processname "steam"
     Powershell -command "Write-Host 'Steam process was found and stopped' -ForegroundColor Red"
    Start-Sleep -s 1
}

if((get-process "ShareX" -ea SilentlyContinue) -eq $Null){
        Powershell -command "Write-Host 'ShareX not running, nothing to stop, moving on...' -ForegroundColor Green"
}

else{
    Stop-Process -processname "ShareX"
    Powershell -command "Write-Host 'ShareX process was found and stopped' -ForegroundColor Red"
    Start-Sleep -s 1
}

if((get-process "idman" -ea SilentlyContinue) -eq $Null){
        Powershell -command "Write-Host 'idman not running, nothing to stop, moving on...' -ForegroundColor Green"
}

else{
    Stop-Process -processname "idman"
    Powershell -command "Write-Host 'idman process was found and stopped' -ForegroundColor Red"
    Start-Sleep -s 1
}

if((get-process "Discord" -ea SilentlyContinue) -eq $Null){
        Powershell -command "Write-Host 'Discord not running, nothing to stop, moving on...' -ForegroundColor Green"
}

else{
    Stop-Process -processname "Discord"
   Powershell -command "Write-Host 'Discord process was found and stopped' -ForegroundColor Red"
    Start-Sleep -s 1
}

if((get-process "Ubisoft Connect" -ea SilentlyContinue) -eq $Null){
        Powershell -command "Write-Host 'Ubisoft Connect not running, nothing to stop, moving on...' -ForegroundColor Green"
}

else{
    Stop-Process -processname "Ubisoft Connect"
    Powershell -command "Write-Host 'Ubisoft Connect process was found and stopped' -ForegroundColor Red"
    Start-Sleep -s 1
}

if((get-process "Origin" -ea SilentlyContinue) -eq $Null){
        Powershell -command "Write-Host 'Origin not running, nothing to stop, moving on...' -ForegroundColor Green"
}

else{
    Stop-Process -processname "Origin"
    Powershell -command "Write-Host 'Origin process was found and stopped' -ForegroundColor Red"
    Start-Sleep -s 1
}

if((get-process "EpicGamesLauncher" -ea SilentlyContinue) -eq $Null){
        Powershell -command "Write-Host 'Epic Games not running, nothing to stop, moving on...' -ForegroundColor Green"
}

else{
    Stop-Process -processname "EpicGamesLauncher"
    Powershell -command "Write-Host 'Epic Games process was found and stopped' -ForegroundColor Red"
    Start-Sleep -s 1
}


Batch file used to run the script above - save with extension .bat:

@echo off
PowerShell.exe -NoProfile -ExecutionPolicy Bypass -File "D:\KillPrograms.ps1"
pause


Run the .bat file above. I made a shortcut to it in Start Menu.

Sources:


_______________________________________


pus acum 3 luni
   
Mrrrr
AdMiN

Inregistrat: acum 17 ani
Postari: 2186
Partial process name:


if((Get-Process | Where-Object { $_.ProcessName -like 'AutoHotkey*' } -ea SilentlyContinue) -eq $Null){
        Powershell -command "Write-Host 'Autohotkey not running, nothing to stop, moving on...' -ForegroundColor Green"
}

else{
    Stop-Process -processname AutoHotkey*
    Powershell -command "Write-Host 'Autohotkey process was found and stopped' -ForegroundColor Red"
    Start-Sleep -s 1
}


_______________________________________


pus acum 3 luni
   
Mrrrr
AdMiN

Inregistrat: acum 17 ani
Postari: 2186
Bat file with countdown 3 seconds:


@echo off
PowerShell.exe -NoProfile -ExecutionPolicy Bypass -File "D:\_Fresh Windows Software\! Mrrrr specific\ps2exe-gui-main-KILL-UNNEC\KillUnnec2024.ps1"
REM pause means wait for key to be pressed in order to close window
REM pause


REM timeout counts down the seconds then closes window
TIMEOUT 3

REM wait 3 seconds alternative, except it doesn't countdown
REM ECHO waiting 3 seconds then closing window...
REM CHOICE /C:AB /D A /T 3 > NUL


Source:


_______________________________________


pus acum 3 luni
   
TRaP
Moderator

Inregistrat: acum 6 ani
Postari: 739
At work I use an add-in for Outlook so that pressing the X button won't exit Outlook, but minimize it to taskbar instead.

In order to quit Outlook without force-closing it, you can use the following PowerShell snippet:

$outlook = Get-Process outlook -ErrorAction SilentlyContinue
if ($outlook) {
    $olApp = New-Object -ComObject Outlook.Application
    $olApp.Quit()
    Remove-Variable olApp
   
    Sleep 15

    if (!$outlook.HasExited) {
        $outlook | Stop-Process -Force
        }
    }
Remove-Variable outlook


Source, also for closing with VBS and with Scheduled Task:


pus acum 3 luni
   
Mrrrr
AdMiN

Inregistrat: acum 17 ani
Postari: 2186
The simple batch file in post #1:

@echo off
PowerShell.exe -NoProfile -ExecutionPolicy Bypass -File "D:\KillPrograms.ps1"
pause


became:


@echo off
echo.
echo This program will kill the following processes:
echo - App_1
echo - App_2
echo - App_3
echo - App_4
echo - App_5
echo - App_6
echo - App_7
echo - App_8
echo - App_9
echo.
echo CONTINUE? (y/n)
set /p Input=Enter y or n:
If /I "%Input%"=="n" goto no2
goto yes
:yes
PowerShell.exe -NoProfile -ExecutionPolicy Bypass -File "D:\KillPrograms.ps1"

REM https://stackoverflow.com/questions/22247390/how-to-get-user-input-batch
@echo off
echo.
echo                                      ---WARNING---
echo.
echo DO YOU WANT YOUR COMPUTER TO SHUTDOWN? (y/n)
set /p Input=Enter y or n:
If /I "%Input%"=="y" goto yes
goto no
:yes
shutdown /s /t 1
exit
:no

echo.
echo DO YOU WANT YOUR COMPUTER TO RESTART THEN? (y/n)
set /p Input=Enter y or n:
If /I "%Input%"=="y" goto yes
goto no2
:yes
shutdown /r /t 1
exit
:no2
TIMEOUT 3


_______________________________________


pus acum 1 luna
   
Pagini: 1  

Mergi la