-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathManageStartupApps.ps1
More file actions
123 lines (104 loc) · 3.48 KB
/
ManageStartupApps.ps1
File metadata and controls
123 lines (104 loc) · 3.48 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<#
.SYNOPSIS
Lists and removes applications from the system startup.
.DESCRIPTION
This script retrieves applications configured to start on system boot
from common startup locations (registry and startup folder) and provides
an option to remove them.
.NOTES
Author: Emanuele Bartolesi
Version: 1.0
Created: 2024-11-17
.EXAMPLE
./ManageStartupApps.ps1
#>
[CmdletBinding()]
param (
[switch]$ListOnly
)
# Function to retrieve startup items from the registry
function Get-StartupAppsFromRegistry {
$StartupPaths = @(
"HKCU:\Software\Microsoft\Windows\CurrentVersion\Run",
"HKLM:\Software\Microsoft\Windows\CurrentVersion\Run"
)
foreach ($Path in $StartupPaths) {
if (Test-Path $Path) {
Get-ItemProperty -Path $Path | ForEach-Object {
[PSCustomObject]@{
Name = $_.PSChildName
Path = $Path
Command = $_.PSObject.Properties.Value
Source = "Registry"
}
}
}
}
}
# Function to retrieve startup items from the startup folder
function Get-StartupAppsFromFolder {
$StartupFolders = @(
"$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup",
"$env:ALLUSERSPROFILE\Microsoft\Windows\Start Menu\Programs\Startup"
)
foreach ($Folder in $StartupFolders) {
if (Test-Path $Folder) {
Get-ChildItem -Path $Folder -File | ForEach-Object {
[PSCustomObject]@{
Name = $_.Name
Path = $Folder
Command = $_.FullName
Source = "Startup Folder"
}
}
}
}
}
# Function to remove a startup item
function Remove-StartupApp {
param (
[string]$Name,
[string]$Source,
[string]$Path
)
try {
switch ($Source) {
"Registry" {
Remove-ItemProperty -Path $Path -Name $Name -ErrorAction Stop
Write-Host "Removed $Name from registry startup path: $Path" -ForegroundColor Green
}
"Startup Folder" {
Remove-Item -Path (Join-Path -Path $Path -ChildPath $Name) -ErrorAction Stop
Write-Host "Removed $Name from startup folder: $Path" -ForegroundColor Green
}
}
} catch {
Write-Warning "Failed to remove $Name: $_"
}
}
# Main script execution
Write-Host "Retrieving startup applications..." -ForegroundColor Cyan
# Retrieve startup apps from both registry and folder
$StartupApps = Get-StartupAppsFromRegistry
$StartupApps += Get-StartupAppsFromFolder
if (-not $StartupApps) {
Write-Host "No startup applications found." -ForegroundColor Yellow
return
}
# Display the list of startup apps
$StartupApps | Format-Table -AutoSize
if ($ListOnly) {
Write-Host "List-only mode enabled. Exiting..." -ForegroundColor Cyan
return
}
# Prompt user to remove apps
$SelectedApps = $StartupApps | Out-GridView -Title "Select Startup Apps to Remove" -PassThru
if (-not $SelectedApps) {
Write-Host "No apps selected for removal. Exiting..." -ForegroundColor Cyan
return
}
# Remove selected apps
foreach ($App in $SelectedApps) {
Remove-StartupApp -Name $App.Name -Source $App.Source -Path $App.Path
}
Write-Host "Startup app management completed." -ForegroundColor Green