A PowerShell-based script for closing specific Windows programs with various options and configurations.
- Multiple execution methods: PowerShell script with batch file wrapper
- Flexible program specification: Command line parameters or configuration file
- Wildcard support: Use
*and?patterns to match multiple processes - Graceful and force close options: Try graceful shutdown first, force if needed
- Logging: All actions are logged with timestamps
- Preview mode: See what would be closed without actually closing
- Verbose output: Detailed information about the closing process
close-programs.ps1- Main PowerShell script with enhanced error handlingclose-programs.bat- Batch file wrapper for easier executionprogram-list.txt- Configuration file with programs to closeclose-programs.log- Log file (created automatically)
# Close programs from configuration file
close-programs.bat
# Close specific programs
close-programs.bat notepad chrome firefox
# Force close with verbose output
close-programs.bat -f -v notepad
# Preview what would be closed
close-programs.bat -w
# Use custom configuration file
close-programs.bat -c my-programs.txt# Close programs from configuration file
.\close-programs.ps1
# Close specific programs
.\close-programs.ps1 -ProcessNames "notepad", "chrome", "firefox"
# Force close programs
.\close-programs.ps1 -ProcessNames "notepad" -Force
# Preview mode
.\close-programs.ps1 -WhatIf
# Verbose output
.\close-programs.ps1 -Verbose
# Custom configuration file
.\close-programs.ps1 -ConfigFile "custom-list.txt"-f,--force- Force close programs without graceful shutdown-v,--verbose- Enable verbose output-w,--whatif- Show what would be closed without actually closing-c,--config- Specify custom configuration file-h,--help- Show help message
-ProcessNames- Array of process names to close-ConfigFile- Path to configuration file (default: program-list.txt)-Force- Force close programs-Verbose- Enable verbose output-WhatIf- Preview mode
Edit program-list.txt to specify which programs should be closed by default:
# Lines starting with # are comments
# List one program name per line (without .exe extension)
notepad
chrome
firefox
calculator
# Wildcard patterns are supported:
*chrome* # Matches all Chrome-related processes
notepad* # Matches notepad and notepad++
*office* # Matches all Office applications
java* # Matches all Java processes
The script supports PowerShell wildcard patterns:
*- Matches any number of characters?- Matches a single character*chrome*- Matches any process containing "chrome"notepad*- Matches processes starting with "notepad"*update*- Matches any process containing "update"
close-programs.bat notepad chrome firefox discordclose-programs.bat "*chrome*"close-programs.bat "java*"close-programs.bat -fclose-programs.bat -wclose-programs.bat -v notepad- Graceful Close First: The script tries to close programs gracefully before forcing
- Process Verification: Checks if processes exist before attempting to close
- Error Handling: Proper error handling and logging
- Preview Mode: Test what would be closed with
-wor-WhatIf - Logging: All actions are logged to
close-programs.log
- Windows with PowerShell (Windows 7/Server 2008 R2 or later)
- PowerShell execution policy allowing script execution
If you get execution policy errors, run this command as Administrator:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser-
"Access is denied" / "Exception calling Kill"
- Run Command Prompt or PowerShell as Administrator
- Some processes (services, system processes) require elevated permissions
- Check the Troubleshooting section below for detailed solutions
-
"Execution of scripts is disabled"
- Run the batch file instead:
close-programs.bat - Or set PowerShell execution policy (see above)
- Run the batch file instead:
-
"Process not found"
- Make sure the process name is correct (without .exe)
- Use Task Manager to verify the exact process name
-
Process won't close gracefully
- Use force mode:
close-programs.bat -f - Some processes may need to be closed from their system tray first
- Use force mode:
Check close-programs.log for detailed information about script execution, including:
- Which programs were found and closed
- Any errors encountered
- Timestamps for all actions
Edit program-list.txt and add program names (one per line, without .exe extension):
# My custom programs
myapp
anotherapp
You can create specialized scripts for different scenarios:
# Gaming session cleanup
close-programs.bat steam discord obs64
# Work day cleanup
close-programs.bat chrome slack teams outlook
# Development cleanup
close-programs.bat code devenv notepad++This project is released under the MIT License. Feel free to modify and distribute as needed.
Problem: Process requires administrator privileges to close
[ERROR] Access denied terminating 'ProcessName' (Owner: SYSTEM\User). Try running as Administrator.
Solutions:
- Right-click Command Prompt → "Run as Administrator", then run
close-programs.bat - Right-click PowerShell → "Run as Administrator"
- Use:
powershell -Command "Start-Process PowerShell -ArgumentList '-ExecutionPolicy Bypass -File close-programs.ps1' -Verb RunAs"
Problem: Trying to close a Windows service process
[WARNING] Skipping process 'ProcessName' (PID: 1234): Windows service: ServiceName
Solutions:
- Stop the service first:
net stop ServiceNameorStop-Service ServiceName - Use Services.msc to stop the service manually
- Some services cannot be stopped (critical system services)
Problem: Process is protected by Windows
[ERROR] Access denied closing 'ProcessName' (Owner: NT AUTHORITY\SYSTEM). Process may be protected.
Solutions:
- These are usually system processes that shouldn't be closed
- Remove from your program list if it's a system process
- Use Task Manager as Administrator if absolutely necessary
Problem: Process exits before we can close it
[INFO] Process 'ProcessName' (PID: 1234) has already exited
Solution: This is normal behavior, no action needed
Always test with preview mode before actual closing:
# Safe preview
close-programs.bat -w
# After confirming, run normally
close-programs.batUse Task Manager to see process details:
- Open Task Manager (Ctrl+Shift+Esc)
- Go to "Details" tab
- Right-click columns → Add "User name"
- Check which user owns the process
- System utilities: Task Manager, Registry Editor
- Security software: Antivirus, Windows Defender
- Hardware utilities: Graphics drivers, system monitoring tools
- Services: Background services, system daemons
MouseWithoutBorders may run with elevated privileges. Options:
- Exit from system tray first
- Run script as Administrator
- Stop the service:
net stop "Mouse without Borders"
# Graceful close
taskkill /IM ProcessName.exe
# Force close
taskkill /F /IM ProcessName.exe
# Close by PID
taskkill /F /PID 1234# Get process info
wmic process where name="ProcessName.exe" get ProcessId,CommandLine
# Terminate process
wmic process where name="ProcessName.exe" delete# Graceful stop
Stop-Process -Name "ProcessName"
# Force stop
Stop-Process -Name "ProcessName" -Force
# Stop by ID
Stop-Process -Id 1234 -ForceFocus on user applications rather than system processes:
# Safe to close (user applications)
notepad
chrome
firefox
vlc
spotify
discord
# Avoid system processes
# svchost
# winlogon
# csrss
When adding new programs to your list:
- Add one at a time
- Test with
-w(preview mode) first - Check if it requires admin rights
- Verify it closes properly
If you accidentally close critical processes:
- Restart Windows - safest option
- Start Task Manager: Ctrl+Shift+Esc
- Run new process: File → Run new task →
explorer.exe - System Restore: If system becomes unstable
Always check close-programs.log for detailed error information:
type close-programs.log | findstr ERROR# List all processes
Get-Process | Sort-Object Name
# Get specific process details
Get-Process ProcessName | Select-Object *
# Check if running as admin
([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)