-
Notifications
You must be signed in to change notification settings - Fork 0
/
slimwin.ps1
194 lines (170 loc) · 7.04 KB
/
slimwin.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# Cargar ensamblado para formularios
Add-Type -AssemblyName System.Windows.Forms
# Crear ventana principal
$form = New-Object System.Windows.Forms.Form
$form.Text = "Debloat Windows 11"
$form.Size = New-Object System.Drawing.Size(400, 500)
$form.StartPosition = "CenterScreen"
# Etiqueta de instrucciones
$label = New-Object System.Windows.Forms.Label
$label.Text = "Selecciona las opciones que deseas aplicar:"
$label.Size = New-Object System.Drawing.Size(350, 20)
$label.Location = New-Object System.Drawing.Point(20, 20)
$form.Controls.Add($label)
# Variables de control
$cancelRequested = $false
$taskRunning = $false
# Botón de cancelar
$buttonCancel = New-Object System.Windows.Forms.Button
$buttonCancel.Text = "Cancelar"
$buttonCancel.Location = New-Object System.Drawing.Point(270, 400)
$buttonCancel.Size = New-Object System.Drawing.Size(100, 30)
$form.Controls.Add($buttonCancel)
# Botón de salir
$buttonExit = New-Object System.Windows.Forms.Button
$buttonExit.Text = "Salir"
$buttonExit.Location = New-Object System.Drawing.Point(150, 400)
$buttonExit.Size = New-Object System.Drawing.Size(100, 30)
$form.Controls.Add($buttonExit)
# Checkbox para cada acción
$checkboxBackup = New-Object System.Windows.Forms.CheckBox
$checkboxBackup.Text = "Crear copia de seguridad"
$checkboxBackup.Location = New-Object System.Drawing.Point(20, 60)
$checkboxBackup.Checked = $true
$form.Controls.Add($checkboxBackup)
$checkboxBloatware = New-Object System.Windows.Forms.CheckBox
$checkboxBloatware.Text = "Eliminar aplicaciones preinstaladas"
$checkboxBloatware.Location = New-Object System.Drawing.Point(20, 100)
$checkboxBloatware.Checked = $true
$form.Controls.Add($checkboxBloatware)
$checkboxServices = New-Object System.Windows.Forms.CheckBox
$checkboxServices.Text = "Deshabilitar servicios innecesarios"
$checkboxServices.Location = New-Object System.Drawing.Point(20, 140)
$checkboxServices.Checked = $true
$form.Controls.Add($checkboxServices)
$checkboxPrivacy = New-Object System.Windows.Forms.CheckBox
$checkboxPrivacy.Text = "Configurar ajustes de privacidad"
$checkboxPrivacy.Location = New-Object System.Drawing.Point(20, 180)
$checkboxPrivacy.Checked = $true
$form.Controls.Add($checkboxPrivacy)
$checkboxClean = New-Object System.Windows.Forms.CheckBox
$checkboxClean.Text = "Liberar espacio en disco"
$checkboxClean.Location = New-Object System.Drawing.Point(20, 220)
$checkboxClean.Checked = $true
$form.Controls.Add($checkboxClean)
# Botón de ejecutar
$buttonExecute = New-Object System.Windows.Forms.Button
$buttonExecute.Text = "Ejecutar"
$buttonExecute.Location = New-Object System.Drawing.Point(20, 400)
$buttonExecute.Size = New-Object System.Drawing.Size(100, 30)
$form.Controls.Add($buttonExecute)
# Función para crear copia de seguridad en bloques más pequeños
function Create-Backup {
if ($cancelRequested) { return }
$taskRunning = $true
$backupPath = "C:\Backup_Windows"
if (-not (Test-Path $backupPath)) {
New-Item -ItemType Directory -Path $backupPath -Force
}
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
# Lista de carpetas a respaldar
$foldersToBackup = @("$env:USERPROFILE\Documents", "$env:USERPROFILE\Desktop", "$env:USERPROFILE\Downloads")
Write-Output "Comenzando copia de seguridad en bloques..."
foreach ($folder in $foldersToBackup) {
if ($cancelRequested) { return }
$folderName = Split-Path -Leaf $folder
$partialZip = Join-Path $backupPath "$folderName_$timestamp.zip"
try {
Compress-Archive -Path $folder -DestinationPath $partialZip -Force
Write-Output "Respaldado: $folder -> $partialZip"
} catch {
Write-Output "Error al respaldar $folder: $_"
}
}
$taskRunning = $false
Write-Output "Copia de seguridad completada."
[System.Windows.Forms.MessageBox]::Show("Copia de seguridad completada en $backupPath", "Información")
}
# Función para eliminar aplicaciones preinstaladas
function Remove-Bloatware {
if ($cancelRequested) { return }
$taskRunning = $true
$appsToRemove = @(
"Microsoft.3DBuilder",
"Microsoft.XboxGameCallableUI",
"Microsoft.ZuneMusic",
"Microsoft.ZuneVideo",
"Microsoft.People",
"Microsoft.BingNews",
"Microsoft.MicrosoftSolitaireCollection"
)
foreach ($app in $appsToRemove) {
if ($cancelRequested) { return }
Get-AppxPackage -Name $app | Remove-AppxPackage -AllUsers -ErrorAction SilentlyContinue
}
$taskRunning = $false
[System.Windows.Forms.MessageBox]::Show("Aplicaciones preinstaladas eliminadas", "Información")
}
# Función para deshabilitar servicios
function Disable-Services {
if ($cancelRequested) { return }
$taskRunning = $true
$servicesToDisable = @(
"DiagTrack", "dmwappushservice", "XboxGipSvc", "xbgm", "XblAuthManager", "XblGameSave"
)
foreach ($service in $servicesToDisable) {
if ($cancelRequested) { return }
Stop-Service -Name $service -Force -ErrorAction SilentlyContinue
Set-Service -Name $service -StartupType Disabled
}
$taskRunning = $false
[System.Windows.Forms.MessageBox]::Show("Servicios innecesarios deshabilitados", "Información")
}
# Función para configurar privacidad
function Configure-Privacy {
if ($cancelRequested) { return }
$taskRunning = $true
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection" -Name "AllowTelemetry" -Value 0
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "CortanaConsent" -Value 0
$taskRunning = $false
[System.Windows.Forms.MessageBox]::Show("Ajustes de privacidad configurados", "Información")
}
# Función para limpiar almacenamiento
function Clean-Storage {
if ($cancelRequested) { return }
$taskRunning = $true
Start-Process -FilePath "cleanmgr.exe" -ArgumentList "/sagerun:1" -NoNewWindow -Wait
$taskRunning = $false
[System.Windows.Forms.MessageBox]::Show("Espacio en disco liberado", "Información")
}
# Acción al presionar "Cancelar"
$buttonCancel.Add_Click({
if ($taskRunning) {
$cancelRequested = $true
[System.Windows.Forms.MessageBox]::Show("Proceso cancelado. Saldrá al terminar la tarea en curso.", "Cancelado")
} else {
[System.Windows.Forms.MessageBox]::Show("No hay procesos en ejecución. Cancelando...", "Cancelado")
$form.Close()
}
})
# Acción al presionar "Salir"
$buttonExit.Add_Click({
$cancelRequested = $true
$form.Close()
})
# Acción al presionar "Ejecutar"
$buttonExecute.Add_Click({
$taskRunning = $true
if ($checkboxBackup.Checked) { Create-Backup }
if ($checkboxBloatware.Checked) { Remove-Bloatware }
if ($checkboxServices.Checked) { Disable-Services }
if ($checkboxPrivacy.Checked) { Configure-Privacy }
if ($checkboxClean.Checked) { Clean-Storage }
if (-not $cancelRequested) {
[System.Windows.Forms.MessageBox]::Show("Script completado. Reinicia tu sistema.", "Finalizado")
}
$taskRunning = $false
$form.Close()
})
# Mostrar la ventana
[void]$form.ShowDialog()