-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwin11_HOME.ps1
More file actions
2080 lines (1784 loc) · 114 KB
/
win11_HOME.ps1
File metadata and controls
2080 lines (1784 loc) · 114 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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# ============================================================
# TITANIUM V8 - WIN11 HOME 26100 (Build 26100.6584)
# - Active Defender with Tamper Protection
# - HVCI active - disabled via DISM
# - Pre-installed bloatware - removed via AppxPackage
# - Microsoft account forced - blocked by policy
# - Defender-powered SmartScreen - reversed sequence
# ============================================================
Write-Host "=== TITANIUM V8 WIN11 HOME 26100 ===" -ForegroundColor Cyan
# ------------------------------------------------------------
# 0. GATEKEEPER + SELF-ELEVATION
# ------------------------------------------------------------
$currentIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
$isSystem = $currentIdentity.Name -eq "NT AUTHORITY\SYSTEM"
$isAdmin = ([Security.Principal.WindowsPrincipal]$currentIdentity).IsInRole(
[Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isSystem -and -not $isAdmin) {
Write-Host "ERROR: Run as administrator or SYSTEM via PowerRun!" -ForegroundColor Red
Pause; exit
}
if ($isAdmin -and -not $isSystem) {
Write-Host "WARN: Run as administrator - some ACL operations require SYSTEM." -ForegroundColor Yellow
Write-Host " For complete results use PowerRun." -ForegroundColor Yellow
}
# ============================================================
# LANGUAGE SYSTEM
# Loads localized strings from .psd1 via Worker
# Fallback: en-US if culture not supported or download fails
# ============================================================
$ScriptName = "win11_HOME"
$LogDate = Get-Date -Format "yyyy-MM-dd_HH-mm"
$LogDateHuman = (Get-Date).ToString("g") # follows system culture
$LogStartTime = Get-Date
$_culture = (Get-UICulture).Name
$_supported = @("it-IT","ru-RU","zh-CN","de-DE","es-ES","fr-FR","pt-BR","tr-TR","pl-PL")
$_langCode = if ($_supported -contains $_culture) { $_culture } else { "en-US" }
$_workerBase = "https://dedo-os.dedonato-paolo.workers.dev"
$Lang = $null
try {
$langContent = (New-Object System.Net.WebClient).DownloadString("$_workerBase/lang/$_langCode")
$Lang = Invoke-Expression $langContent
} catch {}
if (-not $Lang) {
try {
$langContent = (New-Object System.Net.WebClient).DownloadString("$_workerBase/lang/en-US")
$Lang = Invoke-Expression $langContent
} catch {}
}
# Hard fallback if Worker unreachable (offline scenario)
if (-not $Lang) {
$Lang = @{
ScriptName = "win11_HOME"
ReportTitle = "TITANIUM V8 - OPTIMIZATION REPORT"
LabelDate = "Date"; LabelComputer = "Computer"; LabelUser = "User"
LabelWindows = "Windows"; LabelCPU = "CPU"; LabelRAM = "RAM"
LabelPS = "PowerShell"; LabelRunAs = "Run as"
LabelRunAsSystem = "SYSTEM (PowerRun)"; LabelRunAsAdmin = "Administrator"
LabelLogDesktop = "Log Desktop"; LabelDetail = "--- OPERATION DETAIL ---"
RestoreCreating = "[INIT] Creating restore point..."
FooterSummary = "--- FINAL SUMMARY ---"; FooterResult = "RESULT"
FooterSuccess = "COMPLETED SUCCESSFULLY"; FooterWithErrors = "COMPLETED WITH ERRORS"
FooterDuration = "Duration"; FooterMinutes = "min"; FooterSeconds = "sec"
FooterOK = "OK"; FooterWarnings = "Warnings"; FooterErrors = "Errors"
FooterSendFile = "In case of problems, send this file to your technician."
FooterBackupPath = "Log backup:"
SummaryTitle = "=== TITANIUM V8 WIN11 HOME - COMPLETED ==="
SummaryDefender = " -> Defender/SmartScreen/Tamper Protection: DISABLED."
SummaryBloatware = " -> Bloatware Xbox/Teams/OneDrive/Recall: REMOVED."
SummaryMSA = " -> Microsoft Account and Consumer Features: BLOCKED."
SummarySSD = " -> SSD/NVMe: TRIM active, unnecessary writes eliminated."
SummaryPerf = " -> GPU/CPU/I/O Performance Engine: APPLIED."
SummaryReboot = " -> The system will reboot in 12 seconds."
PopupTitle = "Titanium V8 - Completed"
PopupBody = "Optimization complete!`n`nReport saved to Desktop:`n{0}`n`nSend to technician if issues.`n`nPC restarts in seconds."
SearchInfoTitle = "INFORMATION - Windows Search"; SearchInfoEnter = "Press ENTER to continue..."
SearchInfoLine1 = "The script will disable the Windows Search box"
SearchInfoLine2 = "and Microsoft cloud connection."
SearchInfoLine3 = "File search will continue to work"
SearchInfoLine4 = "via EVERYTHING (to be installed)."
SearchInfoLine5 = "Will be disabled:"; SearchInfoLine6 = "- Bing search from taskbar"
SearchInfoLine7 = "- Microsoft cloud suggestions"; SearchInfoLine8 = "- Search box in taskbar"
SearchInfoLine9 = "- WebView2 Search (background)"
WSearchTitle = "WARNING - Windows Search (WSearch)"
WSearchLine1 = "The SEARCH YOUR FILES feature will be DISABLED."
WSearchLine2 = "After disabling you will need to use EVERYTHING"
WSearchLine3 = "to search for files on your PC."
WSearchOptY = "Y = Disable WSearch (recommended with Everything)"
WSearchOptN = "N = Keep WSearch active"
WSearchPrompt = "Disable Windows Search? (Y/N)"
WSearchDisabled = "WSearch: DISABLED. Use Everything to search files."
WSearchKept = "WSearch: KEPT on user request."
WSearchNote1 = "NOTE: use EVERYTHING to search files"
WSearchNote2 = "from script folder: Everything\everything.exe"
WSearchNote3 = "Launch it and drag icon to taskbar."
OneDriveTitle = "Titanium V8 - OneDrive"
OneDriveMsg = "Do you want to disable OneDrive?`nIf No, OneDrive remains active."
OneDriveDisabled = "OneDrive: disabled on user request."
OneDriveKept = "OneDrive: kept active on user request."
}
}
# Log paths use ScriptName for folder and file
$_LogBackupDir = "C:\Windows\Logs\$ScriptName"
$_LogFileName = "${ScriptName}_${LogDate}.txt"
# Detect real user's Desktop path even when running as SYSTEM
$_realUserDesktop = $null
try {
# Method 1: User logged in via WMI
$activeUser = (Get-CimInstance Win32_ComputerSystem -ErrorAction SilentlyContinue).UserName
if ($activeUser -and $activeUser -match '\\') {
$activeUserName = $activeUser.Split('\')[-1]
$candidatePath = "C:\Users\$activeUserName\Desktop"
if (Test-Path $candidatePath) { $_realUserDesktop = $candidatePath }
}
} catch {}
if (-not $_realUserDesktop) {
try {
# Method 2: First non-system user profile in C:\Users
$profiles = Get-ChildItem "C:\Users" -Directory -ErrorAction SilentlyContinue |
Where-Object { $_.Name -notin @("Default","Default User","Public","All Users","SYSTEM") } |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1
if ($profiles) { $_realUserDesktop = Join-Path $profiles.FullName "Desktop" }
} catch {}
}
# Fallback: Public desktop accessible from SYSTEM
if (-not $_realUserDesktop) {
$_realUserDesktop = "C:\Users\Public\Desktop"
}
$DesktopPath = $_realUserDesktop
$LogDesktop = "$DesktopPath\$_LogFileName"
# Backup to Windows/Logs folder (safe, untouched by cleanups)
$LogBackupDir = $_LogBackupDir
if (!(Test-Path $LogBackupDir)) { New-Item -Path $LogBackupDir -ItemType Directory -Force | Out-Null }
$LogBackup = "$LogBackupDir\$_LogFileName"
# Counters
$script:LogWarnings = 0
$script:LogErrors = 0
$script:LogBlocks = 0
$script:LogBlocksOk = 0
# Collect hardware info by header
$_cs = Get-CimInstance Win32_ComputerSystem -ErrorAction SilentlyContinue
$_cpu = Get-CimInstance Win32_Processor -ErrorAction SilentlyContinue | Select-Object -First 1
$_os = Get-CimInstance Win32_OperatingSystem -ErrorAction SilentlyContinue
$_ram = if ($_cs) { [math]::Round($_cs.TotalPhysicalMemory/1GB) } else { "N/D" }
$_cpuName = if ($_cpu) { $_cpu.Name.Trim() } else { "N/D" }
$_osVer = if ($_os) { "$($_os.Caption) - build $($_os.BuildNumber)" } else { "N/D" }
$_pcName = $env:COMPUTERNAME
$_user = if ($activeUser) { $activeUser } else { $env:USERNAME }
$_psVer = $PSVersionTable.PSVersion.ToString()
$_runAs = if ($isSystem) { $Lang.LabelRunAsSystem } else { $Lang.LabelRunAsAdmin }
function Write-Log {
param(
[string]$Message,
[string]$Level = "INFO"
)
$ts = Get-Date -Format "HH:mm:ss"
$line = "[$ts] [$Level] $Message"
# Write to both log files
Add-Content -Path $LogDesktop -Value $line -Encoding UTF8 -ErrorAction SilentlyContinue
Add-Content -Path $LogBackup -Value $line -Encoding UTF8 -ErrorAction SilentlyContinue
# Counters
if ($Level -eq "WARN") { $script:LogWarnings++ }
if ($Level -eq "ERROR") { $script:LogErrors++ }
if ($Level -eq "BLOCK") { $script:LogBlocks++ }
if ($Level -eq "OK") { $script:LogBlocksOk++ }
# Console color based on level
$color = switch ($Level) {
"OK" { "Green" }
"WARN" { "Yellow" }
"ERROR" { "Red" }
"BLOCK" { "Cyan" }
default { "Gray" }
}
Write-Host $line -ForegroundColor $color
}
# Write log header
$header = @"
╔══════════════════════════════════════════════════════════════╗
║ $($Lang.ReportTitle)
╠══════════════════════════════════════════════════════════════╣
║ $($Lang.LabelDate): $LogDateHuman
║ $($Lang.LabelComputer): $_pcName
║ $($Lang.LabelUser): $_user
║ $($Lang.LabelWindows): $_osVer
║ $($Lang.LabelCPU): $_cpuName
║ $($Lang.LabelRAM): $_ram GB
║ $($Lang.LabelPS): $_psVer
║ $($Lang.LabelRunAs): $_runAs
║ $($Lang.LabelLogDesktop): $LogDesktop
╚══════════════════════════════════════════════════════════════╝
$($Lang.LabelDetail)
"@
Add-Content -Path $LogDesktop -Value $header -Encoding UTF8 -ErrorAction SilentlyContinue
Add-Content -Path $LogBackup -Value $header -Encoding UTF8 -ErrorAction SilentlyContinue
Write-Host "[LOG] File di report: $LogDesktop" -ForegroundColor Cyan
# Initial restore point before any major changes
Write-Host $Lang.RestoreCreating -ForegroundColor Cyan
Enable-ComputerRestore -Drive "C:\" -ErrorAction SilentlyContinue
$SrPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore"
if (!(Test-Path $SrPath)) { New-Item -Path $SrPath -Force | Out-Null }
Set-ItemProperty -Path $SrPath -Name "SystemRestorePointCreationFrequency" -Type DWord -Value 0 -Force
Checkpoint-Computer -Description "before system4 win11 home" -RestorePointType "MODIFY_SETTINGS" -ErrorAction SilentlyContinue
# ------------------------------------------------------------
# DEFENDER: SCRIPT PATH EXCLUSION (pre-execution blocks)
# ------------------------------------------------------------
$Sys4ScriptPath = $MyInvocation.MyCommand.Path
if (-not $Sys4ScriptPath) { $Sys4ScriptPath = $PSCommandPath }
$Sys4ExclusionPaths = @(
$Sys4ScriptPath,
"C:\ProgramData\System4"
) | Where-Object { $_ }
Write-Host "[DEFENDER] Added script path exclusion..." -ForegroundColor Cyan
foreach ($excPath in $Sys4ExclusionPaths) {
try {
Add-MpPreference -ExclusionPath $excPath -ErrorAction SilentlyContinue
Write-Host (" Exclusion aggiunta: {0}" -f $excPath) -ForegroundColor DarkGray
} catch {
Write-Host (" WARN exclusion ({0}): {1}" -f $excPath, $_) -ForegroundColor Yellow
}
}
function Remove-Sys4DefenderExclusions {
Write-Host "[DEFENDER] Removing script path exclusions..." -ForegroundColor Cyan
foreach ($excPath in $Sys4ExclusionPaths) {
try {
Remove-MpPreference -ExclusionPath $excPath -ErrorAction SilentlyContinue
Write-Host (" Exclusion rimossa: {0}" -f $excPath) -ForegroundColor DarkGray
} catch {}
}
}
# ------------------------------------------------------------
# GLOBAL FUNCTION: Enable token privileges
# Required for Block 4 and Block 10 (ACL on protected keys)
# ------------------------------------------------------------
function Enable-Privileges {
$code = @'
using System;
using System.Runtime.InteropServices;
public class TokenPriv {
[DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true)]
internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);
[DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true)]
internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);
[DllImport("advapi32.dll", SetLastError=true)]
internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);
[StructLayout(LayoutKind.Sequential, Pack=1)]
internal struct TokPriv1Luid { public int Count; public long Luid; public int Attr; }
internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
internal const int TOKEN_QUERY = 0x00000008;
internal const int TOKEN_ADJUST_PRIVS = 0x00000020;
public static void Enable(string privilege) {
IntPtr hproc = System.Diagnostics.Process.GetCurrentProcess().Handle;
IntPtr htok = IntPtr.Zero;
OpenProcessToken(hproc, TOKEN_ADJUST_PRIVS | TOKEN_QUERY, ref htok);
TokPriv1Luid tp = new TokPriv1Luid();
tp.Count = 1; tp.Luid = 0; tp.Attr = SE_PRIVILEGE_ENABLED;
LookupPrivilegeValue(null, privilege, ref tp.Luid);
AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
}
}
'@
Add-Type -TypeDefinition $code -ErrorAction SilentlyContinue
[TokenPriv]::Enable("SeTakeOwnershipPrivilege")
[TokenPriv]::Enable("SeRestorePrivilege")
[TokenPriv]::Enable("SeBackupPrivilege")
}
# ------------------------------------------------------------
# GLOBAL FUNCTION: Apply Deny SetValue ACL on service key
# Direct method Microsoft.Win32.Registry (bypassSet-Acl)
# ------------------------------------------------------------
function Set-SvcDenyAcl {
param([string]$SvcName)
$regPath = "SYSTEM\CurrentControlSet\Services\$SvcName"
try {
$key = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey(
$regPath,
[Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,
[System.Security.AccessControl.RegistryRights]::ChangePermissions -bor
[System.Security.AccessControl.RegistryRights]::ReadPermissions -bor
[System.Security.AccessControl.RegistryRights]::TakeOwnership
)
if ($null -eq $key) { Write-Host " WARN: impossibile aprire $SvcName" -ForegroundColor Yellow; return }
$acl = $key.GetAccessControl([System.Security.AccessControl.AccessControlSections]::All)
$systemSid = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-18")
$acl.SetOwner($systemSid)
$everyone = New-Object System.Security.Principal.SecurityIdentifier("S-1-1-0")
$denyRule = New-Object System.Security.AccessControl.RegistryAccessRule(
$everyone,
[System.Security.AccessControl.RegistryRights]::SetValue,
[System.Security.AccessControl.InheritanceFlags]::None,
[System.Security.AccessControl.PropagationFlags]::None,
[System.Security.AccessControl.AccessControlType]::Deny
)
$acl.SetAccessRule($denyRule)
$key.SetAccessControl($acl)
$key.Close()
Write-Host " ACL Deny applied on $SvcName" -ForegroundColor Gray
} catch {
Write-Host " WARN: $SvcName - $_" -ForegroundColor Yellow
}
}
function Invoke-SchtasksQuiet {
param([string]$Arguments)
& cmd.exe /c "schtasks $Arguments >nul 2>nul" | Out-Null
}
function Remove-RegValueQuiet {
param(
[string]$Path,
[string]$Name
)
try { Remove-ItemProperty -Path $Path -Name $Name -Force -ErrorAction SilentlyContinue } catch {}
}
function Set-RegDwordQuiet {
param(
[string]$Path,
[string]$Name,
[int]$Value
)
try {
if (!(Test-Path $Path)) { New-Item -Path $Path -Force | Out-Null }
Set-ItemProperty -Path $Path -Name $Name -Value $Value -Type DWord -Force -ErrorAction SilentlyContinue
} catch {}
}
# ------------------------------------------------------------
# GLOBAL FUNCTION: Retrieve active interactive user SID
# ------------------------------------------------------------
function Get-ActiveUserSid {
try {
$activeUser = (Get-CimInstance -ClassName Win32_ComputerSystem -ErrorAction SilentlyContinue).UserName
if ([string]::IsNullOrWhiteSpace($activeUser)) { return $null }
$parts = $activeUser.Split('\')
if ($parts.Count -lt 2) { return $null }
$domain = $parts[0]; $user = $parts[1]
$acct = Get-CimInstance -ClassName Win32_UserAccount -Filter "Name='$user' AND Domain='$domain'" -ErrorAction SilentlyContinue
if ($acct -and $acct.SID) { return $acct.SID }
} catch {}
return $null
}
# ------------------------------------------------------------
# GLOBAL FEATURE: Set TaskbarFrom on all user profiles
# ------------------------------------------------------------
function Set-TaskbarDaEverywhere {
param([int]$Value = 0)
$advKey = "Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
Set-RegDwordQuiet -Path "HKCU:\$advKey" -Name "TaskbarDa" -Value $Value
$activeSid = Get-ActiveUserSid
if ($activeSid) {
Set-RegDwordQuiet -Path "Registry::HKEY_USERS\$activeSid\$advKey" -Name "TaskbarDa" -Value $Value
Write-Host (" Widgets: TaskbarDa={0} su SID utente attivo: {1}" -f $Value, $activeSid) -ForegroundColor DarkGray
} else {
Write-Host " Widgets: Active user SID not detected (no user logged in)." -ForegroundColor DarkGray
}
Set-RegDwordQuiet -Path "Registry::HKEY_USERS\.DEFAULT\$advKey" -Name "TaskbarDa" -Value $Value
}
function Ask-YesNoPopup {
param(
[string]$Title,
[string]$Message
)
try {
Add-Type -AssemblyName System.Windows.Forms -ErrorAction SilentlyContinue
$result = [System.Windows.Forms.MessageBox]::Show(
$Message,
$Title,
[System.Windows.Forms.MessageBoxButtons]::YesNo,
[System.Windows.Forms.MessageBoxIcon]::Question,
[System.Windows.Forms.MessageBoxDefaultButton]::Button2
)
return ($result -eq [System.Windows.Forms.DialogResult]::Yes)
} catch {
$fallback = Read-Host "$Message (S/N)"
return ($fallback -match "^[SsYy]$")
}
}
function Invoke-ZombiePurge {
param([bool]$DisableOneDrive = $true)
# Repeatable purge to prevent reinstallations after updates/installations
$patterns = @("*Copilot*", "*MicrosoftTeams*", "*Teams*", "*OneDrive*", "*Bing*")
foreach ($p in $patterns) {
Get-AppxPackage -AllUsers -Name $p -ErrorAction SilentlyContinue |
Remove-AppxPackage -AllUsers -ErrorAction SilentlyContinue
Get-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue |
Where-Object { $_.DisplayName -like $p -or $_.PackageName -like $p } |
Remove-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue | Out-Null
}
Remove-RegValueQuiet -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" -Name "TeamsMachineInstaller"
if ($DisableOneDrive) {
Remove-RegValueQuiet -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" -Name "OneDrive"
Remove-RegValueQuiet -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" -Name "OneDrive"
Remove-RegValueQuiet -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" -Name "OneDriveSetup"
Remove-RegValueQuiet -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" -Name "OneDriveSetup"
$ODPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\OneDrive"
if (!(Test-Path $ODPath)) { New-Item -Path $ODPath -Force | Out-Null }
Set-ItemProperty -Path $ODPath -Name "DisableFileSyncNGSC" -Value 1 -Force
Stop-Process -Name "OneDrive" -Force -ErrorAction SilentlyContinue
}
Stop-Process -Name "ms-teams","Teams","Copilot" -Force -ErrorAction SilentlyContinue
}
function Invoke-CopilotHardBlock {
# Keeps Edge/WebView2 intact, only blocks Copilot from running
$CopilotExeCandidates = @(
"C:\Program Files (x86)\Microsoft\Copilot\Application\copilot.exe",
"C:\Program Files (x86)\Microsoft\Copilot\Application\msedge_proxy.exe"
)
foreach ($exe in $CopilotExeCandidates) {
if (Test-Path $exe) {
$ruleName = "System4 Block Copilot - " + [System.IO.Path]::GetFileName($exe)
$existing = Get-NetFirewallRule -DisplayName $ruleName -ErrorAction SilentlyContinue
if (-not $existing) {
New-NetFirewallRule -DisplayName $ruleName -Direction Outbound -Program $exe -Action Block -Profile Any -ErrorAction SilentlyContinue | Out-Null
}
}
}
# Disable Copilot-related scheduled tasks without touching Edge core
try {
Get-ScheduledTask -ErrorAction SilentlyContinue |
Where-Object { $_.TaskName -match "Copilot" -or $_.TaskPath -match "Copilot" } |
Disable-ScheduledTask -ErrorAction SilentlyContinue | Out-Null
} catch {}
Stop-Process -Name "copilot","ms-copilot","msedge_proxy" -Force -ErrorAction SilentlyContinue
}
# Enable privileges now (needed from Block 4 onwards)
Enable-Privileges
# ------------------------------------------------------------
# BLOCK 1: LANGUAGE MANAGEMENT
# ------------------------------------------------------------
& {
Write-Host "`n[MODULO] System Language Management..." -ForegroundColor Cyan
Stop-Service -Name "W32Time" -Force -ErrorAction SilentlyContinue
Stop-Service -Name "FontCache" -Force -ErrorAction SilentlyContinue
Stop-Service -Name "LanmanWorkstation" -Force -ErrorAction SilentlyContinue
$KeepLangs = @("it-IT","en-US","en-GB")
Set-WinUserLanguageList -LanguageList $KeepLangs -Force
Set-WinSystemLocale -SystemLocale "it-IT"
Set-WinUILanguageOverride -Language "it-IT"
Start-Service -Name "W32Time" -ErrorAction SilentlyContinue
Start-Service -Name "FontCache" -ErrorAction SilentlyContinue
Start-Service -Name "LanmanWorkstation" -ErrorAction SilentlyContinue
Write-Host "-> Language Module Completed." -ForegroundColor Green
}
# ------------------------------------------------------------
# BLOCK 2: ADAPTIVE MEMORY ENGINE & KERNEL TIMER OPTIMIZER
# ------------------------------------------------------------
& {
Write-Host "`n[MODULO] Hardware Adaptive Memory & Timer Engine..." -ForegroundColor Cyan
# 1. DEEP HARDWARE DETECTION
$CS_Obj = Get-CimInstance Win32_ComputerSystem | Select-Object -First 1
$Proc_Obj = Get-CimInstance Win32_Processor | Select-Object -First 1
$RAM_Data = Get-CimInstance Win32_PhysicalMemory
$TotalRAM_MB = [math]::Round($CS_Obj.TotalPhysicalMemory / 1MB)
$RAM_GB = [math]::Round($TotalRAM_MB / 1024)
$CpuCores = $Proc_Obj.NumberOfCores
$RAMSpeed = if ($RAM_Data) { ($RAM_Data | Measure-Object -Property Speed -Maximum).Maximum } else { 2400 }
Write-Host " Hardware: $CpuCores Core Fisici | $RAM_GB GB RAM @ $RAMSpeed MHz" -ForegroundColor Gray
# 2. TIMER OPTIMIZATION (HPET & TICK)
# Safe strategy for bare metal with VirtualBox/Supremo/USB audio
Write-Host " System Timer Optimization (Low Latency)..." -ForegroundColor Gray
# Detect if Hyper-V is active (VirtualBox does not coexist with Hyper-V)
$HyperVActive = $false
try {
$hvStatus = (Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -ErrorAction SilentlyContinue).State
if ($hvStatus -eq "Enabled") { $HyperVActive = $true }
} catch { $HyperVActive = $false }
# Detect USB audio devices - sensitive to timers
$UsbAudioPresent = $false
try {
$usbAudio = Get-PnpDevice -ErrorAction SilentlyContinue | Where-Object {
$_.Class -eq "Media" -and $_.InstanceId -match "USB"
}
if ($usbAudio) { $UsbAudioPresent = $true }
} catch { $UsbAudioPresent = $false }
# Detect CPU generation for TSC invariant
$CpuName = $Proc_Obj.Name
$TscInvariant = $CpuName -match "i[3579]-[0-9]{4,}|Ryzen|Xeon|Core.Ultra|i[3579]-1[0-9]{4}"
if ($HyperVActive) {
# Hyper-V active: DO NOT touch useplatformclock - VirtualBox depends on it.
& bcdedit.exe /set disabledynamictick yes 2>$null
& bcdedit.exe /deletevalue useplatformclock 2>$null
& bcdedit.exe /deletevalue useplatformtick 2>$null
Write-Host " Timer: Hyper-V detected - safe mode for VirtualBox." -ForegroundColor Yellow
} elseif ($UsbAudioPresent) {
# USB audio present (soundbar, DAC, interfaces): DO NOT disable dynamic tick
# disabledynamictick alters USB audio interrupts, causing distortion
& bcdedit.exe /set useplatformclock no 2>$null
& bcdedit.exe /deletevalue disabledynamictick 2>$null # Ripristina default
& bcdedit.exe /deletevalue useplatformtick 2>$null
Write-Host " Timer: Audio USB rilevato - dynamic tick preservato per stabilita' audio." -ForegroundColor Yellow
if ($usbAudio) { Write-Host (" Dispositivo protetto: {0}" -f $usbAudio.FriendlyName) -ForegroundColor Gray }
} elseif ($TscInvariant) {
# Modern CPU, no USB audio, no Hyper-V: full optimization
& bcdedit.exe /set useplatformclock no 2>$null
& bcdedit.exe /set disabledynamictick yes 2>$null
& bcdedit.exe /deletevalue useplatformtick 2>$null
Write-Host " Timer: TSC invariant - HPET disabled, minimal latency." -ForegroundColor Gray
} else {
# Old or unrecognized CPU: conservative configuration
& bcdedit.exe /set useplatformclock yes 2>$null
& bcdedit.exe /set disabledynamictick yes 2>$null
& bcdedit.exe /deletevalue useplatformtick 2>$null
Write-Host " Timer: Legacy CPU - HPET preserved for stability." -ForegroundColor Yellow
}
Write-Host (" CPU: {0} | Hyper-V: {1} | TSC: {2} | USB Audio: {3}" -f $CpuName, $HyperVActive, $TscInvariant, $UsbAudioPresent) -ForegroundColor Gray
# NOTE: Global Timer Resolution Requests removed - causes distortion on USB/jack audio
# Restore if present from previous versions of the script
$KernelTimerPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\kernel"
Remove-ItemProperty -Path $KernelTimerPath -Name "GlobalTimerResolutionRequests" -ErrorAction SilentlyContinue
# Restore generic USB audio drivers if accidentally removed
& pnputil.exe /add-driver "$env:SystemRoot\INF\wdmaudio.inf" /install /force 2>$null | Out-Null
& pnputil.exe /add-driver "$env:SystemRoot\INF\usbaudio.inf" /install /force 2>$null | Out-Null
Write-Host " Driver audio USB generici: verificati e ripristinati." -ForegroundColor Gray
Stop-Service -Name "SysMain","WSearch","Spooler" -Force -ErrorAction SilentlyContinue
# 3. ADAPTIVE PAGEFILE LOGIC
if ($RAM_GB -le 4) {
$MinP = 2048; $MaxP = 4096; $Profile = "LOW RAM"
} elseif ($RAM_GB -le 8) {
$MinP = 2048; $MaxP = 8192; $Profile = "MEDIUM RAM"
} elseif ($RAM_GB -ge 16 -and $RAMSpeed -ge 3000) {
$MinP = 1024; $MaxP = 16384; $Profile = "HIGH-END"
} else {
$MinP = 1024; $MaxP = 8192; $Profile = "BALANCED"
}
$RegMM = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management"
Set-ItemProperty -Path $RegMM -Name "PagingFiles" -Value "C:\pagefile.sys $MinP $MaxP" -Force
# 4. SVCHOST SPLIT LOGIC - granular table for RAM
$thresholdMap = @{
4 = 400000
6 = 600000
8 = 800000
12 = 1200000
16 = 1600000
24 = 2400000
32 = 3200000
64 = 6400000
}
$availableKeys = $thresholdMap.Keys | Where-Object { $_ -le $RAM_GB } | Sort-Object -Descending
if ($availableKeys.Count -gt 0) {
$svcValue = $thresholdMap[$availableKeys[0]]
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control" -Name "SvcHostSplitThresholdInKB" -Value $svcValue -Force
Write-Host " SvcHostSplitThreshold: $svcValue KB (RAM: $RAM_GB GB)." -ForegroundColor Gray
} else {
Write-Host " WARN: Unmapped RAM ($RAM_GB GB), SvcHostSplitThreshold unchanged." -ForegroundColor Yellow
}
# 5. MEMORY COMPRESSION (MMAgent)
if (Get-Command Disable-MMAgent -ErrorAction SilentlyContinue) {
if ($RAM_GB -ge 16 -or $CpuCores -le 4) {
Disable-MMAgent -MemoryCompression -ErrorAction SilentlyContinue
$CompStatus = "OFF"
} else {
Enable-MMAgent -MemoryCompression -ErrorAction SilentlyContinue
$CompStatus = "ON"
}
} else { $CompStatus = "N/D" }
# WSearch NOT rebooted - permanently disabled in Block 16
# SysMain NOT rebooted to Home - already disabled by ISO or Block 22
Start-Service -Name "Spooler" -ErrorAction SilentlyContinue
Write-Host ("-> Profilo {0}: Timer Ottimizzati | SvcHost {1} {2} KB | Compressione {3}" -f $Profile, $(if($RAM_GB -ge 4){"Split"}else{"Unified"}), $svcValue, $CompStatus) -ForegroundColor Green
}
# ============================================================
# BLOCK 3: CPU MITIGATIONS & VBS/HVCI KILL
# On Win11 Home HVCI is active - requires DISM to disable it
# ============================================================
& {
Write-Host "`n[MODULO] Disabilitazione Mitigazioni CPU & VBS/HVCI..." -ForegroundColor Red
$MMPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management"
Set-ItemProperty -Path $MMPath -Name "FeatureSettingsOverride" -Value 3 -Force
Set-ItemProperty -Path $MMPath -Name "FeatureSettingsOverrideMask" -Value 3 -Force
$DGPath = "HKLM:\SYSTEM\CurrentControlSet\Control\DeviceGuard"
if (!(Test-Path $DGPath)) { New-Item -Path $DGPath -Force | Out-Null }
Set-ItemProperty -Path $DGPath -Name "EnableVirtualizationBasedSecurity" -Value 0 -Force
Set-ItemProperty -Path $DGPath -Name "HypervisorEnforcedCodeIntegrity" -Value 0 -Force -ErrorAction SilentlyContinue
# HVCI via DISM - required on Win11 Home where registry alone is not enough
Write-Host " Disabling HVCI via DISM..." -ForegroundColor Gray
& dism.exe /online /Disable-Feature /FeatureName:IsolatedUserMode /NoRestart 2>$null | Out-Null
& dism.exe /online /Disable-Feature /FeatureName:Microsoft-Hyper-V-Hypervisor /NoRestart 2>$null | Out-Null
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\DmaGuard" -Name "Enabled" -Value 0 -Force -ErrorAction SilentlyContinue
# Disable Core Isolation via Registry
$CIPath = "HKLM:\SYSTEM\CurrentControlSet\Control\DeviceGuard\Scenarios\HypervisorEnforcedCodeIntegrity"
if (!(Test-Path $CIPath)) { New-Item -Path $CIPath -Force | Out-Null }
Set-ItemProperty -Path $CIPath -Name "Enabled" -Value 0 -Force
Set-ItemProperty -Path $CIPath -Name "WasEnabledBy" -Value 0 -Force -ErrorAction SilentlyContinue
Write-Host "-> CPU Mitigations & VBS/HVCI Disabled." -ForegroundColor Green
}
# ============================================================
# BLOCK 4: FTH & DPS - CHECK & HARD LOCK
# Use Microsoft.Win32.Registry instead of Set-Acl
# ============================================================
& {
Write-Host "`n[MODULO] Checking FTH and DPS status..." -ForegroundColor Cyan
$FTH_Enabled = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\FTH" -Name "Enabled" -ErrorAction SilentlyContinue).Enabled
$DPS_Start = (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\dps" -Name "Start" -ErrorAction SilentlyContinue).Start
if ($FTH_Enabled -eq 0 -and $DPS_Start -eq 4) {
Write-Host "-> FTH e DPS gia' disabilitati. Procedo al Lock." -ForegroundColor Green
} else {
Write-Host "-> FTH o DPS attivi. Disabilitazione forzata..." -ForegroundColor Yellow
Stop-Service -Name "dps" -Force -ErrorAction SilentlyContinue
if (!(Test-Path "HKLM:\SOFTWARE\Microsoft\FTH")) { New-Item -Path "HKLM:\SOFTWARE\Microsoft\FTH" -Force | Out-Null }
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\FTH" -Name "Enabled" -Value 0 -Force
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\dps" -Name "Start" -Value 4 -Force
}
Write-Host "[SYS] Applicazione Hard Lock DPS..." -ForegroundColor Cyan
Set-SvcDenyAcl -SvcName "dps"
Write-Host "-> Hard Lock DPS applicato." -ForegroundColor Green
}
# ============================================================
# BLOCK 5: NETWORK & DNS UNIFICATION
# ============================================================
& {
Write-Host "`n[MODULO] Network and DNS Unification (Adobe/Autodesk AI Ready)..." -ForegroundColor Cyan
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -Name "NameServer" -Value "8.8.8.8 8.8.4.4" -Force
$DNS_Pol = "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\DNSClient"
if (!(Test-Path $DNS_Pol)) { New-Item -Path $DNS_Pol -Force | Out-Null }
Set-ItemProperty -Path $DNS_Pol -Name "NameServer" -Value "8.8.8.8,8.8.4.4" -Force
$FW_Rules = "HKLM:\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules"
$RuleOS = "v2.30|Action=Block|Active=TRUE|Dir=Out|Protocol=6|RPort=443|RA4=13.107.4.52|RA4=52.114.128.21|Name=Titanium_OS_Silent_Only|"
Set-ItemProperty -Path $FW_Rules -Name "BlockWinOS_Telemetry" -Value $RuleOS -Force
$WPAD = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Wpad"
if (!(Test-Path $WPAD)) { New-Item -Path $WPAD -Force | Out-Null }
Set-ItemProperty -Path $WPAD -Name "WpadDecision" -Value 0 -Force
& ipconfig /flushdns | Out-Null
Write-Host "-> Network configured. AI (Adobe/CAD) servers unlocked via Google DNS." -ForegroundColor Green
}
# ============================================================
# BLOCK 5b: NETWORK ADVANCED TWEAKS & WiFi OPTIMIZER
# ============================================================
& {
Write-Host "`n[MODULO] Network Advanced Tweaks & WiFi Optimizer..." -ForegroundColor Cyan
# --------------------------------------------------------
# LANMANSERVER - SMB Optimization
# --------------------------------------------------------
$SmbPath = "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters"
Set-ItemProperty -Path $SmbPath -Name "SharingViolationDelay" -Value 0 -Force
Set-ItemProperty -Path $SmbPath -Name "SharingViolationRetries" -Value 0 -Force
Set-ItemProperty -Path $SmbPath -Name "IRPStackSize" -Value 32 -Force
Set-ItemProperty -Path $SmbPath -Name "autodisconnect" -Value 0xFFFFFFFF -Force
Set-ItemProperty -Path $SmbPath -Name "Size" -Value 3 -Force
Set-ItemProperty -Path $SmbPath -Name "TCP1323Opts" -Value 1 -Force
Write-Host " SMB: Optimized (IRPStack 32, no SharingViolation, autodisconnect OFF)." -ForegroundColor Gray
# --------------------------------------------------------
# DNS CACHE - clear error cache
# --------------------------------------------------------
$DnsPath = "HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters"
if (!(Test-Path $DnsPath)) { New-Item -Path $DnsPath -Force | Out-Null }
Set-ItemProperty -Path $DnsPath -Name "NegativeCacheTime" -Value 0 -Force
Set-ItemProperty -Path $DnsPath -Name "NegativeSOACacheTime" -Value 0 -Force
Set-ItemProperty -Path $DnsPath -Name "NetFailureCacheTime" -Value 0 -Force
Set-ItemProperty -Path $DnsPath -Name "MaximumUdpPacketSize" -Value 4864 -Force
Write-Host " DNS: error cache cleared, UDP packet size 4864." -ForegroundColor Gray
# --------------------------------------------------------
# TCP/IP PARAMETERS - connection optimization
# --------------------------------------------------------
$TcpPath = "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters"
Set-ItemProperty -Path $TcpPath -Name "TcpTimedWaitDelay" -Value 30 -Force
Set-ItemProperty -Path $TcpPath -Name "MaxUserPort" -Value 65534 -Force
Set-ItemProperty -Path $TcpPath -Name "TcpMaxDataRetransmissions" -Value 5 -Force
Set-ItemProperty -Path $TcpPath -Name "TcpCreateAndConnectTcbRateLimitDepth" -Value 0 -Force
Set-ItemProperty -Path $TcpPath -Name "StrictTimeWaitSeqCheck" -Value 1 -Force
Set-ItemProperty -Path $TcpPath -Name "GlobalMaxTcpWindowSize" -Value 65535 -Force
Set-ItemProperty -Path $TcpPath -Name "TcpWindowSize" -Value 65535 -Force
Set-ItemProperty -Path $TcpPath -Name "MaxFreeTcbs" -Value 65536 -Force
Set-ItemProperty -Path $TcpPath -Name "MaxHashTableSize" -Value 65535 -Force
Set-ItemProperty -Path $TcpPath -Name "Tcp1323Opts" -Value 3 -Force
Set-ItemProperty -Path $TcpPath -Name "EnablePMTUDiscovery" -Value 1 -Force
Set-ItemProperty -Path $TcpPath -Name "EnablePMTUBHDetect" -Value 0 -Force
Set-ItemProperty -Path $TcpPath -Name "DefaultTTL" -Value 64 -Force
Set-ItemProperty -Path $TcpPath -Name "EnableDynamicBacklog" -Value 1 -Force
Set-ItemProperty -Path $TcpPath -Name "MinimumDynamicBacklog" -Value 50 -Force
Set-ItemProperty -Path $TcpPath -Name "MaximumDynamicBacklog" -Value 1003 -Force
Set-ItemProperty -Path $TcpPath -Name "DynamicBacklogGrowthDelta" -Value 10 -Force
Set-ItemProperty -Path $TcpPath -Name "KeepAliveTime" -Value 7200000 -Force
Set-ItemProperty -Path $TcpPath -Name "QualifyingDestinationThreshold" -Value 3 -Force
Write-Host " TCP/IP: finestra 65535, TTL 64, dynamic backlog ON, port max 65534." -ForegroundColor Gray
# --------------------------------------------------------
# TcpAckFrequency on all interfaces
# --------------------------------------------------------
$InterfacesPath = "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces"
$interfaces = Get-ChildItem -Path $InterfacesPath -ErrorAction SilentlyContinue
$count = 0
foreach ($iface in $interfaces) {
Set-ItemProperty -Path $iface.PSPath -Name "TcpAckFrequency" -Value 1 -Force -ErrorAction SilentlyContinue
Set-ItemProperty -Path $iface.PSPath -Name "TcpNoDelay" -Value 1 -Force -ErrorAction SilentlyContinue
$count++
}
Write-Host (" TcpAckFrequency/NoDelay: applied on {0} interfaces." -f $count) -ForegroundColor Gray
# --------------------------------------------------------
# NDIS RSS
# --------------------------------------------------------
$NdisPath = "HKLM:\SYSTEM\CurrentControlSet\Services\Ndis\Parameters"
if (!(Test-Path $NdisPath)) { New-Item -Path $NdisPath -Force | Out-Null }
Set-ItemProperty -Path $NdisPath -Name "MaxNumRssThreads" -Value 18 -Force
Set-ItemProperty -Path $NdisPath -Name "MaxNumRssCpus" -Value 6 -Force
Write-Host " NDIS RSS: 18 thread, 6 CPU." -ForegroundColor Gray
# --------------------------------------------------------
# AFD KeepAlive
# --------------------------------------------------------
$AfdPath = "HKLM:\SYSTEM\CurrentControlSet\Services\AFD\Parameters"
if (!(Test-Path $AfdPath)) { New-Item -Path $AfdPath -Force | Out-Null }
Set-ItemProperty -Path $AfdPath -Name "KeepAliveInterval" -Value 1 -Force
Write-Host " AFD KeepAliveInterval: 1." -ForegroundColor Gray
# --------------------------------------------------------
# PSCHED QoS - no bandwidth reserve
# --------------------------------------------------------
$PschedPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Psched"
if (!(Test-Path $PschedPath)) { New-Item -Path $PschedPath -Force | Out-Null }
Set-ItemProperty -Path $PschedPath -Name "NonBestEffortLimit" -Value 0 -Force
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows" -Name "Psched" -ErrorAction SilentlyContinue
Write-Host " Psched QoS: bandwidth reserve reset." -ForegroundColor Gray
# --------------------------------------------------------
# WiFi OPTIMIZER
# --------------------------------------------------------
$wifiAdapter = Get-NetAdapter -ErrorAction SilentlyContinue |
Where-Object { $_.PhysicalMediaType -eq "802.11" -and $_.Status -ne "Not Present" } |
Select-Object -First 1
if ($wifiAdapter) {
Write-Host (" WiFi rilevato: {0}" -f $wifiAdapter.InterfaceDescription) -ForegroundColor Gray
Disable-NetAdapterPowerManagement -Name $wifiAdapter.Name -ErrorAction SilentlyContinue
Set-NetAdapterAdvancedProperty -Name $wifiAdapter.Name -RegistryKeyword "PowerSavingMode" -RegistryValue 0 -ErrorAction SilentlyContinue
Set-NetAdapterAdvancedProperty -Name $wifiAdapter.Name -RegistryKeyword "Band" -RegistryValue 2 -ErrorAction SilentlyContinue
Set-NetAdapterAdvancedProperty -Name $wifiAdapter.Name -RegistryKeyword "RoamingAggressiveness" -RegistryValue 1 -ErrorAction SilentlyContinue
Set-NetAdapterAdvancedProperty -Name $wifiAdapter.Name -RegistryKeyword "*ReceiveBuffers" -RegistryValue 512 -ErrorAction SilentlyContinue
Set-NetAdapterAdvancedProperty -Name $wifiAdapter.Name -RegistryKeyword "*TransmitBuffers" -RegistryValue 512 -ErrorAction SilentlyContinue
Set-NetAdapterAdvancedProperty -Name $wifiAdapter.Name -RegistryKeyword "TransmitPower" -RegistryValue 5 -ErrorAction SilentlyContinue
& powercfg /setacvalueindex SCHEME_CURRENT 19cbb8fa-5279-450e-9fac-8a3d5fedd0c1 12bbebe6-58d6-4636-95bb-3217ef867c1a 0 2>$null
& powercfg /setactive SCHEME_CURRENT 2>$null
& netsh wlan set autoconfig enabled=yes interface=$wifiAdapter.Name 2>$null | Out-Null
Write-Host " WiFi: 5GHz preferred, power saving OFF, minimal roaming, 512 buffer." -ForegroundColor Gray
} else {
Write-Host " WiFi: No cards detected - optimization skipped." -ForegroundColor Yellow
}
Write-Host "-> Network Advanced Tweaks & WiFi Optimizer completed." -ForegroundColor Green
}
# ============================================================
# BLOCK 6: NETWORK OPTIMIZATION & KERNEL TUNING
# ============================================================
& {
Write-Host "`n[MODULO] Network Optimization & Kernel Tuning..." -ForegroundColor Cyan
$TcpPath = "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters"
Set-ItemProperty -Path $TcpPath -Name "TcpAckFrequency" -Value 1 -Force
Set-ItemProperty -Path $TcpPath -Name "TCPNoDelay" -Value 1 -Force
Set-ItemProperty -Path $TcpPath -Name "EnableRSS" -Value 1 -Force
Set-ItemProperty -Path $TcpPath -Name "DisableTaskOffload" -Value 0 -Force
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\NetBT\Parameters" -Name "NoNameReleaseOnDemand" -Value 1 -Force
& bcdedit.exe /set "{current}" nx OptOut 2>$null
& bcdedit.exe /set "{current}" bootmenupolicy legacy 2>$null
# NOTA: hypervisorlaunchtype NOT modified on Win11 Home
# On Home without Hyper-V installed it generates warnings and can cause instability
# Win11 modern shell/taskbar richiedono UAC attivo per comportamento coerente
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "EnableLUA" -Value 1 -Force
& ipconfig /flushdns | Out-Null
Write-Host "-> Tuning applied. Device & Internet connectivity PRESERVED." -ForegroundColor Green
}
# ============================================================
# BLOCK 7: EDGE/COPILOT PURGE & WEBVIEW2 READINESS
# ============================================================
& {
Write-Host "`n[MODULO] Edge Armoring & Copilot Removal..." -ForegroundColor Yellow
# Copilot Removal - build 26100 Win11 Home
Write-Host "-> Deleting Copilot packages..." -ForegroundColor Gray
# Remove all existing Copilot packages (name varies by version)
Get-AppxPackage -AllUsers | Where-Object { $_.Name -match "Copilot" } |
Remove-AppxPackage -AllUsers -ErrorAction SilentlyContinue
Get-AppxProvisionedPackage -Online | Where-Object { $_.PackageName -match "Copilot" } |
Remove-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue
# Fallback DISM per build 26100
dism.exe /online /Remove-ProvisionedAppxPackage /PackageName:Microsoft.Windows.Ai.Copilot.App_1.0.3.0_neutral_~_8wekyb3d8bbwe 2>$null | Out-Null
dism.exe /online /Remove-ProvisionedAppxPackage /PackageName:Microsoft.Copilot_1.0.0.0_neutral_~_8wekyb3d8bbwe 2>$null | Out-Null
$CopilotPol = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsCopilot"
if (!(Test-Path $CopilotPol)) { New-Item -Path $CopilotPol -Force | Out-Null }
Set-ItemProperty -Path $CopilotPol -Name "TurnOffWindowsCopilot" -Value 1 -Force
Set-ItemProperty -Path $CopilotPol -Name "TurnOffCopilot" -Value 1 -Force -ErrorAction SilentlyContinue
# Edge Copilot/Sidebar: explicit block (copilot often reappears from here)
$EdgePolMain = "HKLM:\SOFTWARE\Policies\Microsoft\Edge"
if (!(Test-Path $EdgePolMain)) { New-Item -Path $EdgePolMain -Force | Out-Null }
Set-ItemProperty -Path $EdgePolMain -Name "HubsSidebarEnabled" -Value 0 -Force -ErrorAction SilentlyContinue
Set-ItemProperty -Path $EdgePolMain -Name "StandaloneHubsSidebarEnabled" -Value 0 -Force -ErrorAction SilentlyContinue
Set-ItemProperty -Path $EdgePolMain -Name "CopilotPageContext" -Value 0 -Force -ErrorAction SilentlyContinue
Set-ItemProperty -Path $EdgePolMain -Name "EdgeEntraCopilotPageContext" -Value 0 -Force -ErrorAction SilentlyContinue
Set-ItemProperty -Path $EdgePolMain -Name "ShowCopilotButton" -Value 0 -Force -ErrorAction SilentlyContinue
Invoke-CopilotHardBlock
# Edge Reinstall Blocked
$EdgeUpdate = "HKLM:\SOFTWARE\Microsoft\EdgeUpdate"
if (!(Test-Path $EdgeUpdate)) { New-Item -Path $EdgeUpdate -Force | Out-Null }
Set-ItemProperty -Path $EdgeUpdate -Name "DoNotUpdateToEdgeWithChromium" -Value 1 -Force
$EdgePol = "HKLM:\SOFTWARE\Policies\Microsoft\EdgeUpdate"
if (!(Test-Path $EdgePol)) { New-Item -Path $EdgePol -Force | Out-Null }
Set-ItemProperty -Path $EdgePol -Name "DoNotUpdateToEdgeWithChromium" -Value 1 -Force
# Edge Services disabled (WebView2 remains functional)
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\edgeupdate" -Name "Start" -Value 4 -Force -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\edgeupdatem" -Name "Start" -Value 4 -Force -ErrorAction SilentlyContinue
# Edge Task Cleanup
Invoke-SchtasksQuiet '/Delete /TN "MicrosoftEdgeUpdateTaskMachineCore" /F'
Invoke-SchtasksQuiet '/Delete /TN "MicrosoftEdgeUpdateTaskMachineUA" /F'
Write-Host "-> Edge/Copilot rimossi e blindati. WebView2 integro." -ForegroundColor Green
}
# ============================================================
# BLOCK 8: TELEMETRY & DATA COLLECTION
# ============================================================
& {
Write-Host "`n[MODULO] Disabling Telemetry & WerSvc..." -ForegroundColor Yellow
Stop-Service -Name "DiagTrack" -Force -ErrorAction SilentlyContinue
Stop-Service -Name "dmwappushservice" -Force -ErrorAction SilentlyContinue
Stop-Service -Name "WerSvc" -Force -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\DiagTrack" -Name "Start" -Value 4 -Force
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\dmwappushservice" -Name "Start" -Value 4 -Force
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\WerSvc" -Name "Start" -Value 4 -Force
$WerPol = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Error Reporting"
if (!(Test-Path $WerPol)) { New-Item -Path $WerPol -Force | Out-Null }
Set-ItemProperty -Path $WerPol -Name "Disabled" -Value 1 -Force
Write-Host "-> Telemetry and Error Reporting eliminated." -ForegroundColor Green
}
# ============================================================
# BLOCK 9: TELEMETRY GHOST TRIGGERS
# Win11 Home: added anti-reactivation policies and tasks
# ============================================================
& {
Write-Host "`n[MODULO] Total Telemetry Clearing & Ghost Triggers..." -ForegroundColor Red
$TelPolicy = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection"
if (!(Test-Path $TelPolicy)) { New-Item -Path $TelPolicy -Force | Out-Null }
Set-ItemProperty -Path $TelPolicy -Name "AllowTelemetry" -Value 0 -Force
Set-ItemProperty -Path $TelPolicy -Name "MaxTelemetryAllowed" -Value 0 -Force -ErrorAction SilentlyContinue
Set-ItemProperty -Path $TelPolicy -Name "DisableTelemetryOptInSettingsUx" -Value 1 -Force -ErrorAction SilentlyContinue
Set-ItemProperty -Path $TelPolicy -Name "DoNotShowFeedbackNotifications" -Value 1 -Force -ErrorAction SilentlyContinue
$CEIPPath = "HKLM:\SOFTWARE\Policies\Microsoft\SQMClient\Windows"
if (!(Test-Path $CEIPPath)) { New-Item -Path $CEIPPath -Force | Out-Null }
Set-ItemProperty -Path $CEIPPath -Name "CEIPEnable" -Value 0 -Force -ErrorAction SilentlyContinue
$AppCompatPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\AppCompat"
if (!(Test-Path $AppCompatPath)) { New-Item -Path $AppCompatPath -Force | Out-Null }
Set-ItemProperty -Path $AppCompatPath -Name "AITEnable" -Value 0 -Force -ErrorAction SilentlyContinue
Set-ItemProperty -Path $AppCompatPath -Name "DisableInventory" -Value 1 -Force -ErrorAction SilentlyContinue
& sc.exe triggerinfo DiagTrack delete | Out-Null
& sc.exe triggerinfo WerSvc delete | Out-Null
& sc.exe triggerinfo dmwappushservice delete | Out-Null
Stop-Service -Name "DiagTrack" -Force -ErrorAction SilentlyContinue
Stop-Service -Name "dmwappushservice" -Force -ErrorAction SilentlyContinue
Stop-Service -Name "WerSvc" -Force -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\DiagTrack" -Name "Start" -Value 4 -Force
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\dmwappushservice" -Name "Start" -Value 4 -Force
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\WerSvc" -Name "Start" -Value 4 -Force
# Scheduled tasks that can reactivate data collection on Home
$TelemetryTasks = @(
"Microsoft\Windows\Application Experience\Microsoft Compatibility Appraiser"
"Microsoft\Windows\Application Experience\ProgramDataUpdater"
"Microsoft\Windows\Application Experience\StartupAppTask"
"Microsoft\Windows\Autochk\Proxy"
"Microsoft\Windows\Customer Experience Improvement Program\Consolidator"
"Microsoft\Windows\Customer Experience Improvement Program\UsbCeip"
"Microsoft\Windows\DiskDiagnostic\Microsoft-Windows-DiskDiagnosticDataCollector"
"Microsoft\Windows\Feedback\Siuf\DmClient"
"Microsoft\Windows\Feedback\Siuf\DmClientOnScenarioDownload"
)
foreach ($t in $TelemetryTasks) {
Invoke-SchtasksQuiet "/change /tn `"$t`" /disable"
}
Write-Host "-> Telemetria tombata, trigger eliminati e task invasivi disattivati." -ForegroundColor Green
}
# ============================================================
# BLOCK 10: WINDOWS UPDATE & DRIVER BLOCK
# - wuauserv: Start=4 only without ACL (compatible with WU-Control)
# ============================================================
& {
Write-Host "`n[MODULO] BLOCK Driver & Hard Lock Windows Update..." -ForegroundColor Yellow
# 1. BLOCK DRIVER - create key if it doesn't exist
$DriverSearchPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DriverSearching"
if (!(Test-Path $DriverSearchPath)) { New-Item -Path $DriverSearchPath -Force | Out-Null }
Set-ItemProperty -Path $DriverSearchPath -Name "SearchOrderConfig" -Value 0 -Force
$DevInstall = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"
if (!(Test-Path $DevInstall)) { New-Item -Path $DevInstall -Force | Out-Null }
Set-ItemProperty -Path $DevInstall -Name "ExcludeWUDriversInQualityUpdate" -Value 1 -Force
# 2. WU CONFIGURATION (Target 24H2 & No Auto Update)
$WU_AU = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU"
if (!(Test-Path $WU_AU)) { New-Item -Path $WU_AU -Force | Out-Null }
Set-ItemProperty -Path $WU_AU -Name "AUOptions" -Value 2 -Force
Set-ItemProperty -Path $WU_AU -Name "NoAutoUpdate" -Value 1 -Force
Set-ItemProperty -Path $DevInstall -Name "TargetReleaseVersion" -Value 1 -Force