-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
WinRice.ps1
3713 lines (3303 loc) · 130 KB
/
WinRice.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
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
# This file is a part of the WinRice software
# Copyright (c) 2020-2024 Pratyaksh Mehrotra <[email protected]>
# All rights reserved.
# Default preset
$tasks = @(
### Maintenance Tasks ###
"WinRice",
"OSBuildInfo",
"CreateSystemRestore",
"Activity",
### Apps & Features ###
"AppsFeatures",
# "InstallVCLibs",
# "UninstallVCLibs",
"InstallWinGet",
# "InstallNanaZip",
# "UninstallNanaZip",
"InstallFlowLauncher",
# "UninstallFlowLauncher",
"WinGetImport",
"Winstall",
# "Winuninstall"
"InstallHEVC",
# "UninstallHEVC"
"InstallWSL", "Activity",
# "UninstallWSL",
"InstalldotNET3.5", "Activity",
# "UninstalldotNET3.5",
"InstallSandbox",
# "UninstallSandbox",
"UninstallApps", "Activity",
"WebApps",
"UnpinStartTiles", "Activity",
"UnpinAppsFromTaskbar",
"UninstallOneDrive", "Activity",
# "InstallOneDrive",
"UninstallFeatures", "Activity",
# "InstallFeatures", "Activity",
"ChangesDone",
### Privacy ###
"PrivacySecurity",
# "DisableActivityHistory",
# "EnableActivityHistory",
"DisableAdvertisingID",
# "EnableAdvertisingID",
# "DisableBackgroundApps",
# "EnableBackgroundApps",
"DisableErrorReporting",
# "EnableErrorReporting",
"DisableFeedback",
# "EnableFeedback",
"DisableInkHarvesting",
# "EnableInkHarvesting",
"DisableLangAccess",
# "EnableLangAccess",
# "DisableLocationTracking",
# "EnableLocationTracking",
# "DisableMapUpdates",
# "EnableMapsUpdates",
"DisableSpeechRecognition",
# "EnableSpeechRecognition",
"DisableSilentInstallApps",
# "EnableSilentInstallApps",
"HideSuggestedContentInSettings",
# "ShowSuggestedContentInSettings",
"DisableAdsInStart",
# "EnableAdsInStart",
"DisableTailoredExperiences",
# "EnableTailoredExperiences",s
"TelemetryRequired",
"TelemetryOptional",
"EnableClipboard",
# "DisableClipboard",
### Security ###
# "AutoLoginPostUpdate",
"StayOnLockscreenPostUpdate",
# "DisableVBS",
# "EnableVBS",
"DisableLogonCredential",
# "EnableLogonCredential",
"DisableLLMNR",
# "EnableLLMNR",
"EnableSEHOP",
# "DisableSEHOP",
"DisableWPAD",
# "EnableWPAD",
"EnableLSAProtection"
# "DisableLSAProtection"
"DisableScriptHost"
# "EnableScriptHost"
"DisableOfficeOLE",
# "EnableOfficeOLE",
"ChangesDone",
### OS ###
"OS",
# "DisableStorageSense",
# "EnableStorageSense",
# "DisableReserves",
# "EnableReserves",
"EnableLongPath",
# "DisableLongPath",
"RestorePowerOptions",
"DisableAutoplay",
# "EnableAutoplay",
"DisableAutorun",
# "EnableAutorun",
"DisableHibernation",
# "EnableHibernation",
"BIOSTimeUTC",
# "BIOSTimeLocal",
"EnableNumLock",
# "DisableNumLock",
# "DisableServices",
# "EnableServices",
"DisableTasks",
# "DisableTasks",
"DisableAMDTasks",
# "EnableAMDTasks",
"SetupWindowsUpdate",
# "ResetWindowsUpdate",
"DisableDeviceInstallation",
# "EnableDeviceInstallation",
# "EnablePowerdownAfterShutdown",
# "DisablePowerdownAfterShutdown",
"DisableWindowsTipsNotifications",
# "EnableWindowsTipsNotifications",
"DisableWindowsWelcomeExperience",
# "EnableWindowsWelcomeExperience",
"ChangesDone",
### Windows Explorer ###
"WindowsExplorer",
# "EnablePrtScrToSnip",
"DisablePrtScrSnip",
"EnableExtensions",
# "DisableExtensions",
"DisableRecentFilesInQuickAccess",
# "ShowRecentFilesInQuickAccess",
"DisableStickyKeys",
# "EnableStickyKeys",
"SetExplorerThisPC",
# "SetExplorerQuickAccess",
"FixAppHoverPreviewThreshold",
# "RevertAppHoverPreviewThreshold",
"Disable3DObjects",
# "Enable3DObjects",
"DisableSearch",
# "EnableSearch"
"DisableSearchView",
# "EnableTaskView",
"DisableCortana",
# "EnableCortana",
"DisableMeetNow",
# "EnableMeetNow",
"DisableNI",
# "EnableNI", (News and Interests)
"DisableWidgets",
# "EnableWidgets",
"DisableChat",
# "EnableChat",
"ChangesDone",
### Tasks after successful run ###
"Activity",
"Success"
)
# Reverting changes: https://github.com/pratyakshm/WinRice/wiki/Reverting-changes.
# Core functions
function check($test) {
if ($test -like "y" -or $test -like "yeah" -or $test -like "yes" -or $test -like "yep" -or $test -like "yea" -or $test -like "yah") {
return $true
}
elseif ($test -like "n" -or $test -like "nope" -or $test -like "no" -or $test -like "nada" -or $test -like "nah" -or $test -like "naw") {
return $false
}
}
function wrexit {
Write-Host "WinRice will now exit."
Start-Sleep -Seconds 2
exit
}
function ask($question) {
Read-Host $question
Start-Sleep -Milliseconds 100
}
function space {
Write-Host " "
}
function print($text) {
Write-Host $text
# Sleep for 150 milliseconds because I am a menace
Start-Sleep -Milliseconds 150
}
function RunWithProgress {
param(
[Parameter(Mandatory = $true)]
[string]
$Text,
[Parameter(Mandatory = $true)]
[ScriptBlock]
$Task,
[Parameter(Mandatory = $false)]
[Boolean]
$Exit = $false
)
$spinner = '\', '|', '/', '-', '\', '|', '/', '-'
$endtext = $text
# Run given scriptblock in bg
$job = Start-Job -ScriptBlock $Task
# Spin while job is running
do {
foreach ($s in $spinner) {
Write-Host -NoNewline "`r [$s] $text"
Start-Sleep -Milliseconds 150
}
}
while ($job.State -eq "Running")
# Get output
$result = Receive-Job -Job $job
# Filter result
if ($result -eq $false -or $null -eq $result) {
# Failure indicator
$ind = '-'
$color = "DarkRed"
$fail = $true
}
else {
# Success indicator
$ind = '+'
$color = "DarkGreen"
}
Write-Host -NoNewline -ForegroundColor $color "`r [$ind] "; Write-Host "$endtext"
# Exit on failure
if ($Exit -and $fail) { wrexit }
return $result
}
# Did you read the docs? (Funny stuff).
$hasReadDoc = ask "By proceeding ahead, you acknowledge that you have read and understood the program documentation. [y/n]"
if (!(check($hasReadDoc))) {
print "You (the user) have not read the program documentation. WinRice will now exit."
exit
}
# Core functions ---
if (!(Test-Path C:\WinRice)) {
New-Item C:\WinRice -ItemType Directory | Out-Null
}
# Start logging
Start-Transcript -OutputDirectory "C:\WinRice" | Out-Null
# Store OS details
$CurrentVersionPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
$CurrentBuild = Get-ItemPropertyValue $CurrentVersionPath -Name CurrentBuild
$DisplayVersion = Get-ItemPropertyValue $CurrentVersionPath -Name DisplayVersion -ErrorAction SilentlyContinue
$ProductNameCore = (Get-WmiObject -class Win32_OperatingSystem).Caption
$ProductName = $ProductNameCore.TrimStart("Microsoft ")
$ProductNameCore = $null
$OSBuildCore = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Update\TargetingInfo\Installed\Client.OS.rs2.amd64" -Name Version
$OSBuild = $OSBuildCore.TrimStart("10.0")
$BuildBranch = Get-ItemPropertyValue $CurrentVersionPath -Name BuildBranch
$hkeyuser = (Get-CimInstance -ClassName Win32_UserAccount | Where-Object -FilterScript { $_.Name -eq $env:USERNAME }).SID
$Insider = (Get-Item -Path "HKLM:\SOFTWARE\Microsoft\WindowsSelfHost\Applicability").Property -contains "IsBuildFlightingEnabled" -or (Get-Item -Path "HKLM:\SOFTWARE\Microsoft\WindowsSelfHost\Applicability").Property -contains "BranchName"
# Change window title
$host.UI.RawUI.WindowTitle = "pratyakshm's WinRice"
# Display Information
Clear-Host
print "WinRice pre-execution environment"
Start-Sleep -Milliseconds 20
space
print "Copyright (c) Pratyaksh Mehrotra and contributors"
Start-Sleep -Milliseconds 20
print "https://github.com/pratyakshm/WinRice"
space
Start-Sleep -Milliseconds 100
$ProgressPreference = 'SilentlyContinue'
$ErrorActionPreference = 'SilentlyContinue'
$WarningPreference = 'SilentlyContinue'
# Begin checks
Write-Host "Beginning checks..."
# Check 1: If supported OS build.
$oscheck = {
$CurrentBuild = Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name CurrentBuild
if ($CurrentBuild -lt 19045) {
return $false
}
elseif ($CurrentBuild -ge 19045) {
return $true
}
}
RunWithProgress -Text "[1/5] Windows version is supported" -Task $oscheck -Exit $true | Out-Null
# Check 2: If session is elevated.
$isadmin = {
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$admin = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
return $admin
}
RunWithProgress -Text "[2/5] Session is elevated" -Task $isadmin -Exit $true | Out-Null
# Check 3: Internet Connection.
$isonline = {
Import-Module BitsTransfer
Start-BitsTransfer https://raw.githubusercontent.com/WinRice/Files/main/File.txt
if (Test-Path File.txt) {
Remove-Item File.txt
return $true
}
elseif (!(Test-Path File.txt)) {
return $false | Out-Null
}
}
RunWithProgress -Text "[3/5] Device is connected to the Internet" -Task $isonline -Exit $true | Out-Null
# Check 4: Device form-factor (https://devblogs.microsoft.com/scripting/hey-scripting-guy-weekend-scripter-how-can-i-use-wmi-to-detect-laptops/).
if (Get-WmiObject -Class Win32_SystemEnclosure | Where-Object { $_.ChassisTypes -eq 9 -or $_.ChassisTypes -eq 10 -or $_.ChassisTypes -eq 14 }) {
$isLaptop = $true
}
# Task 1: Import Appx Module to PowerShell if necessary.
$pwshver = {
Import-Module -Name Appx -UseWindowsPowerShell -WarningAction "SilentlyContinue" | Out-Null
return $true
}
RunWithProgress -Text "[4/5] Setting up PowerShell" -Task $pwshver -Exit $true | Out-Null
# Check 5: Check for pending restarts (part of code used here was picked from https://thesysadminchannel.com/remotely-check-pending-reboot-status-powershell).
$isrestartpending = {
param (
[Parameter(
Mandatory = $false,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
Position = 0
)]
[string[]] $ComputerName = $env:COMPUTERNAME
)
ForEach ($Computer in $ComputerName) {
$PendingReboot = $false
$HKLM = [UInt32] "0x80000002"
$WMI_Reg = [WMIClass] "\\$Computer\root\default:StdRegProv"
if ($WMI_Reg) {
if (($WMI_Reg.EnumKey($HKLM, "SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\")).sNames -contains 'RebootPending') { $PendingReboot = $true }
if (($WMI_Reg.EnumKey($HKLM, "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\")).sNames -contains 'RebootRequired') { $PendingReboot = $true }
# Check for SCCM namespace.
$SCCM_Namespace = Get-WmiObject -Namespace ROOT\CCM\ClientSDK -List -ComputerName $Computer -ErrorAction Ignore
if ($SCCM_Namespace) {
if (([WmiClass]"\\$Computer\ROOT\CCM\ClientSDK:CCM_ClientUtilities").DetermineIfRebootPending().RebootPending -eq $true) { $PendingReboot = $true }
}
if ($PendingReboot -eq $true) {
return $false
}
else {
return $true
}
}
}
}
# Clear variables.
$WMI_Reg = $null
$SCCM_Namespace = $null
RunWithProgress -Text "[5/5] Device session is fresh" -Task $isrestartpending -Exit $true | Out-Null
# Conclude checks.
Start-Sleep -Milliseconds 100
Write-Host "Completed checks." -ForegroundColor green
space
# Declare Express Settings.
$uninstallapps = "y"
if ((Test-Path uninstallapps.txt) -or (Test-Path UninstallApps.txt) -or (Test-Path Uninstallapps.txt)) {
$uninstallmethod = "list"
}
$uninstallfeatures = "y"
$systemrestore = "y"
$systemwidepolicies = "y"
# Print Express Settings.
print "Express Settings:"
$settings = @(
"A set of non-essential apps will be uninstalled."
"A set of non-essential features will be uninstalled."
"Configure specific changes that apply to all users in this device."
)
ForEach ($setting in $settings) {
print " $setting"
}
if ($CurrentBuild -ge 22000) {
Write-Host " Widgets will not be removed."
}
if (!($Insider) -and (Get-WindowsEdition -Online | Where-Object -FilterScript { $_.Edition -like "Enterprise*" -or $_.Edition -eq "Education" -or $_.Edition -eq "Professional" })) {
$dwu = "y"
$au = "y"
print " Windows automatic updates will be disabled."
print " Windows quality updates will be delayed by 4 days and feature updates will be delayed by 20 days."
}
elseif ($Insider) {
print " Windows Update policies are left unchanged in Windows pre-release software."
}
space
print "To learn more, visit https://github.com/pratyakshm/WinRice/blob/main/doc/Main-brief.md."
space
$customize = ask "Do you want to proceed with Express Settings? [Y/n]"
if (!(check($customize))) {
space
print "Please take your time to answer the questions below in order to save user config."
print "Press Enter to proceed after answering a question."
space
space
# App Deployment
print "APP DEPLOYMENT"
$installapps = ask "Do you want to install apps using WinGet? [y/N]"
if (check($installapps)) {
$installusing = ask "Okay, do you want to use (1) winget import or (2) Winstall? [1/2]"
}
elseif ((!($installapps))) {
print " No apps will be installed."
}
if ($installusing -eq "1") {
print " Apps WILL be installed using: winget import."
}
elseif ($installusing -eq "2") {
$fileName = "Winstall.txt"
$faqLink = "https://github.com/pratyakshm/WinRice/blob/main/doc/winget/winstall.md"
$filePath = "$PWD\Winstall.txt"
if (Test-Path -Path $filePath -PathType Leaf) {
$content = Get-Content -Path $filePath
if ($null -eq $content -or $content.Length -eq 0) {
Write-Host "For a tutorial on creating the '$fileName' file, please visit: $faqLink"
Start-Process -FilePath "notepad.exe" -ArgumentList $filePath
}
}
else {
New-Item -ItemType File -Path $fileName -Force | Out-Null
Write-Host "For a tutorial on creating the '$fileName' file, please visit: $faqLink"
Start-Process -FilePath "notepad.exe" -ArgumentList $fileName -Wait
}
}
$installflowlauncher = ask "Do you want to install Flow Launcher? [y/N]"
if (check($installflowlauncher)) {
$installflowlauncher = "y"
}
$uninstallapps = ask "Do you want to uninstall non-essential apps? [Y/n]"
if (!($uninstallapps)) {
$uninstallapps = "y"
print "No input detected, non-essential apps WILL be uninstalled."
}
elseif (check($uninstallapps)) {
if ((Test-Path uninstallapps.txt) -or (Test-Path UninstallApps.txt) -or (Test-Path Uninstallapps.txt)) {
$uninstallmethod = "list"
}
elseif (!(Test-Path uninstallapps.txt) -or (!(Test-Path UninstallApps.txt)) -or (!(Test-Path Uninstallapps.txt))) {
$uninstallmethod = ask "Do you want to select which apps to uninstall? [y/N]"
}
$uninstallod = ask "Do you want to uninstall Microsoft OneDrive? [y/N]"
}
space
# Feature Deployment
print "FEATURE DEPLOYMENT"
$uninstallfeatures = ask "Do you want to uninstall non-essential optional features? [Y/n]"
if (!($uninstallfeatures)) {
$uninstallfeatures = "y"
print " NO input detected, non-essential features WILL be uninstalled."
}
if ($CurrentBuild -ge 22000) {
$widgets = ask "Do you want to uninstall Widgets [y/N]"
}
$netfx3 = ask "Do you want to install .NET 3.5? (used for running legacy programs) [y/N]"
$wsl = ask "Do you want to install Windows Subsystem for Linux? [y/N]"
$sandbox = ask "Do you want to install Windows Sandbox? [y/N]"
# OS Changes
if ( (!($Insider)) -and (Get-WindowsEdition -Online | Where-Object -FilterScript { $_.Edition -like "Enterprise*" -or $_.Edition -eq "Education" -or $_.Edition -eq "Professional" }) ) {
space
print "WINDOWS UPDATE"
$dwu = ask "Do you want to delay Windows updates by a few days? [Y/n]"
$au = ask "Do you want to turn off automatic updates? [Y/n]"
$drivers = ask "Do you want to turn off driver updates from Windows Update? [y/N]"
}
space
$UseUTSCWhenFollowBIOSTime = ask "Do you want Windows to use UTC when it follows BIOS time? Warning: This may have unintended consequences. [y/N]"
if (!($UseUTSCWhenFollowBIOSTime)) {
$UseUTSCWhenFollowBIOSTime = "n"
}
Write-Host "For some changes to take proper effect, they must be applied to all users in this device."
$systemwidepolicies = ask "Do you want to apply those changes? [Y/n]"
$systemrestore = ask "Do you want to create a system restore point? [Y/n]"
print "------------------------------- "
space
space
# REPRINT CONFIG TO USER
Write-Host "To sum it up, you've chosen to: "
## App Installation
if (check($installapps)) {
Write-Host " - Install apps using " -NoNewline -ForegroundColor Cyan
if ($installusing -like "2") {
Write-Host "Winstall." -ForegroundColor Cyan
}
elseif ($installusing -like "1") {
Write-Host "winget import method." -ForegroundColor Cyan
}
}
## App Uninstallation
if (check($uninstallapps)) {
Write-Host " - Uninstall non-essential apps" -NoNewline -ForegroundColor Cyan
if ($uninstallmethod -like "list") {
Write-Host " using a custom List." -ForegroundColor Cyan
}
elseif (check($uninstallmethod)) {
Write-Host " which you will select later on." -ForegroundColor Cyan
}
elseif (!(check($uninstallmethod)) -and (check($uninstallapps))) {
Write-Host " from our predefined list." -ForegroundColor Cyan
}
}
if (check($uninstallod)) {
Write-Host " - Uninstall OneDrive." -ForegroundColor Cyan
}
## Feature Uninstallation
if (check($uninstallfeatures)) {
Write-Host " - Uninstall non-essential features." -ForegroundColor Cyan
}
if (check($widgets)) {
Write-Host " - Uninstall Widgets." -ForegroundColor Cyan
}
## Feature Installation
if (check($netfx3)) {
Write-Host " - Install .NET 3.5." -ForegroundColor Cyan
}
if (check($wsl)) {
Write-Host " - Install WSL." -ForegroundColor Cyan
}
if (check($sandbox)) {
Write-Host " - Install Windows Sandbox." -ForegroundColor Cyan
}
# Extras
if (!(check($systemwidepolicies))) {
Write-Host " - Not configure specific changes that apply to all users in this device." -ForegroundColor Yellow
}
elseif (check($systemwidepolicies)) {
Write-Host " - Configure specific changes that apply to all users in this device." -ForegroundColor Cyan
}
if (!(check($systemrestore))) {
Write-Host " - Not create a System Restore point." -ForegroundColor Yellow
}
elseif (check($systemrestore)) {
Write-Host " - Create a System restore point." -ForegroundColor Cyan
}
if (check($UseUTSCWhenFollowBIOSTime)) {
Write-Host " - Set Windows to use UTC when following BIOS time." -ForegroundColor DarkRed
}
# Windows Update
if ((check($au)) -or (check($dwu)) -or (check($drivers))) {
space
Write-Host "You have chosen these Windows Update policies:"
}
if (check($au)) {
Write-Host " - Disable automatic updates." -ForegroundColor Cyan
}
if (check($dwu)) {
Write-Host " - Delay Windows quality updates by 4 days and feature updates by 20 days." -ForegroundColor Cyan
}
if (check($drivers)) {
Write-Host " - Disable driver delivery via Windows Update." -ForegroundColor Cyan
}
space
Write-Host "If this configuration is correct, " -NoNewline
Write-Host "press any key to go ahead." -ForegroundColor Green
Write-Host "If this configuration is not correct, restart WinRice and create a new one."
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
}
print "Starting WinRice..."
# Intro.
function WinRice {
Clear-Host
print "pratyakshm's WinRice"
space
print "Copyright (c) Pratyaksh Mehrotra and contributors"
print "https://github.com/pratyakshm/WinRice"
Start-Sleep 1
}
# OS Build.
function OSBuildInfo {
space
# If Windows 11 (OS build is greater than or equal to 22000)
if ($CurrentBuild -ge 22000) {
# If a Windows Insider
if ($Insider) {
print "$ProductName Insider Preview"
print "OS Build: $OSBuild, Channel: $DisplayVersion, Branch: $BuildBranch"
}
# If on Retail / prod build
else {
print "$ProductName $DisplayVersion"
print "OS Build: $OSBuild, Channel: General Availability, Branch: $BuildBranch"
}
}
# If Windows 10 (OS build is lesser than 22000)
elseif ($CurrentBuild -lt 22000) {
print "$ProductName $DisplayVersion"
print "OS Build: $OSBuildCore, Branch: $BuildBranch" # Windows Insiders on Windows 10 are not considered due to less number of users.
}
space
print "---------------------------------------------------"
Start-Sleep 1
}
# Changes performed.
function ChangesDone {
space
print "---------------------------"
print " CHANGES PERFORMED "
print "---------------------------"
Start-Sleep 1
}
# Create a system restore point with type MODIFY_SETTINGS.
function CreateSystemRestore {
$ProgressPreference = 'SilentlyContinue'
if (!(check($systemrestore))) {
return
}
space
print "Creating a system restore point..."
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" -Name SystemRestorePointCreationFrequency -Type DWord -Value 0 -Force
Enable-ComputerRestore -Drive $env:SystemDrive
Checkpoint-Computer -Description "WinRice" -RestorePointType "MODIFY_SETTINGS" -WarningAction SilentlyContinue
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" -Name SystemRestorePointCreationFrequency -Type DWord -Value 1440 -Force
Disable-ComputerRestore -Drive $env:SystemDrive
print "Created system restore point."
}
# Prevent the console output from freezing by emulating backspace key. (https://github.com/farag2/Windows-10-Sophia-Script/blob/master/Sophia/PowerShell%205.1/Module/Sophia.psm1#L728-L767)
function Activity {
# Sleep for 500ms.
Start-Sleep -Milliseconds 500
Add-Type -AssemblyName System.Windows.Forms
$SetForegroundWindow = @{
Namespace = "WinAPI"
Name = "ForegroundWindow"
Language = "CSharp"
MemberDefinition = @"
[DllImport("user32.dll")]
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
"@
}
if (-not ("WinAPI.ForegroundWindow" -as [type])) {
Add-Type @SetForegroundWindow
}
Get-Process | Where-Object -FilterScript { $_.MainWindowTitle -like "*PowerShell*" -or $_.MainWindowTitle -like "*pratyakshm's WinRice*" -or $_.MainWindowTitle -like "*pwsh*" } | ForEach-Object -Process {
# Show window if minimized.
[WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10) | Out-Null
Start-Sleep -Milliseconds 10
# Move the console window to the foreground.
[WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle) | Out-Null
Start-Sleep -Milliseconds 10
# Emulate Backspace key.
[System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}")
}
}
###################################
######### APPS & FEATURES #########
###################################
# Update status
function AppsFeatures {
space
print "-------------------------"
print " APPS & FEATURES "
print "-------------------------"
}
# Install VCLibs packages .
function InstallVCLibs {
$ProgressPreference = 'SilentlyContinue'
# Create new folder and set location.
if (!(Test-Path WinRice)) {
New-Item WinRice -ItemType Directory | out-Null
$currentdir = $(Get-Location).Path; $dir = "$currentdir/WinRice"; Set-Location $dir
}
else {
Set-Location WinRice
}
# Download VCLibs.
print "Updating Visual C++ Libraries..."
$VCLibs = "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx"
$VCLibsUWP = "https://github.com/WinRice/Files/raw/main/Microsoft.VCLibs.140.00.UWPDesktop_8wekyb3d8bbwe.Appx"
Start-BitsTransfer $VCLibs ; Start-BitsTransfer $VCLibsUWP
# Install VCLibs.
Add-AppxPackage "Microsoft.VCLibs.x64.14.00.Desktop.appx" ; Add-AppxPackage "Microsoft.VCLibs.140.00.UWPDesktop_8wekyb3d8bbwe.Appx"
Set-Location ..
Remove-Item WinRice -Recurse -Force
# Get-Command VCLibs, if it works then print success message.
if ((Get-AppxPackage *UWPDesktop*).Version -ge 14.0.30035.0) {
print "Updated Visual C++ Libraries."
return
}
else {
print "Failed to update Visual C++ Libraries."
}
}
function UninstallVCLibs {
if (!(Get-AppxPackage *VCLibs*)) {
print "Visual C++ Libraries are not present on this device."
return
}
space
print "Uninstalling Visual C++ Libraries..."
Get-AppxPackage *VCLibs* | Remove-AppxPackage
if (Get-AppxPackage *VCLibs*) {
print "Failed to uninstall Visual C++ Libraries."
return
}
print "Uninstalled Visual C++ Libraries."
}
# Install WinGet (Windows Package Manager)
function InstallWinGet {
$ErrorActionPreference = 'SilentlyContinue'
$ProgressPreference = 'SilentlyContinue'
if (Get-Command winget) {
return
}
space
print "Installing WinGet..."
Start-BitsTransfer https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle
Add-AppxPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle
Remove-Item Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle
if (!(Get-Command winget)) {
print "Failed to install WinGet."
return
}
print "Installed WinGet."
}
# Install NanaZip.
function InstallNanaZip {
space
if (!(Get-Command winget)) {
print "WinGet is not installed. Couldn't install NanaZip."
return
}
if (Get-AppxPackage *NanaZip*) {
print "Skipped NanaZip installation because it is already installed on this device."
return
}
print "Installing NanaZip... (https://github.com/M2Team/NanaZip)"
winget install 9N8G7TSCL18R --accept-source-agreements --accept-package-agreements | Out-Null
print "Installed NanaZip."
}
# Uninstall NanaZip.
function UninstallNanaZip {
space
print "Uninstalling NanaZip..."
winget uninstall 40174MouriNaruto.NanaZip_gnj4mf6z9tkrc --accept-package-agreements --accept-source-agreements | Out-Null
print "Uninstalled NanaZip."
}
function InstallFlowLauncher {
if (!(check($installflowlauncher))) {
return
}
print "Installing Flow Launcher..."
winget install Flow-Launcher.Flow-Launcher
# Check if Flow Launcher is successfully installed.
$packageId = "Flow-Launcher.Flow-Launcher"
$installedPackages = winget list
if ($installedPackages -match $packageId) {
print "Flow Launcher is installed."
} else {
print "Failed to install Flow Launcher."
return
}
print "Customizing Flow Launcher..."
# Stop Flow Launcher running processes and remove Settings backup to ensure no unintended overwrite
Stop-Process -Name "flow.launcher" -Force
# Declare settings files locations
$settingsFolderPath = "$env:APPDATA\FlowLauncher\Settings"
$settingsPath = Join-Path -Path $settingsFolderPath -ChildPath "Settings.json"
$backupPath = Join-Path -Path $settingsFolderPath -ChildPath "Settings.json.bak"
# Delete the backup file to avoid unintended overwrite
Remove-Item -Path $backupPath -Force -ErrorAction SilentlyContinue
# Download the onsetGlaze theme for Flow
$url = "https://raw.githubusercontent.com/abhidahal/onsetGlaze.flow/main/OnsetGlaze.xaml"
$outputPath = "$env:APPDATA\Roaming\FlowLauncher\Themes\OnsetGlaze.xaml"
Invoke-WebRequest -Uri $url -OutFile $outputPath
# Update to OnsetGlaze Theme
$newThemeValue = "OnsetGlaze"
$jsonContent = Get-Content -Path $settingsPath | ConvertFrom-Json
$jsonContent.Theme = $newThemeValue
$jsonContent | ConvertTo-Json -Depth 100 | Set-Content -Path $settingsPath
# Disable unnecessary plugins
$pluginsToDisable = @(
"CEA0FDFC6D3B4085823D60DC76F28855",
"572be03c74c642baae319fc283e561a8",
"6A122269676E40EB86EB543B945932B9",
"9f8f9b14-2518-4907-b211-35ab6290dee7",
"D409510CD0D2481F853690A07E6DC426",
"0308FD86DE0A4DEE8D62B9B535370992",
"565B73353DBF4806919830B9202EE3BF",
"5043CETYU6A748679OPA02D27D99677A"
)
function DisablePlugins {
param(
[Parameter(Mandatory=$true)]
[System.Management.Automation.PSObject]$Object
)
$Object.PSObject.Properties | ForEach-Object {
if ($_.Value -is [System.Management.Automation.PSObject]) {
DisablePlugins -Object $_.Value
}
elseif ($_.Name -eq "ID" -and $pluginsToDisable -contains $_.Value) {
$Object.Disabled = $true
}
}
}
$jsonContent = Get-Content -Path $settingsPath | ConvertFrom-Json
DisablePlugins -Object $jsonContent.PluginSettings.Plugins
$jsonContent | ConvertTo-Json -Depth 100 | Set-Content -Path $settingsPath
print "Customization performed: "
print " – Set Theme to OnsetGlaze."
print " – Disabled the following plugins:"
print " – Browser Bookmarks"
print " – Calculator"
print " – Explorer"
print " – Plugin Indicator"
print " – Plugins Manager"
print " – Shell"
print " – URL"
print " – Web Searches"
print " – Windows Settings"
print "You may change these preferences later in Flow Launcher Settings."
}
function UninstallFlowLauncher {
print "Uninstalling Flow Launcher..."
Stop-Process -Name "flow.launcher" -Force
winget uninstall Flow-Launcher.Flow-Launcher
print "Uninstalled Flow Launcher."
}
# Use winget import (part of code used here was picked from https://devblogs.microsoft.com/scripting/hey-scripting-guy-can-i-open-a-file-dialog-box-with-windows-powershell/)
function WinGetImport {
if (($installusing -like "2") -or (!($installusing))) {
return
}
if (!(Get-Command winget)) {
print "WinGet is not installed. Please install WinGet first before using winget import."
return
}
space
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
print "WinGet Import"
print "Select the exported JSON from File Picker UI"
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.InitialDirectory = $initialDirectory
$OpenFileDialog.Filter = "JSON (*.json)| *.json"
$OpenFileDialog.ShowDialog() | Out-Null
if ($OpenFileDialog.FileName) {
print "Starting winget import..."
winget import $OpenFileDialog.FileName --accept-package-agreements --accept-source-agreements | Out-Null
}
elseif (!($OpenFileDialog.FileName)) {
print "No JSON selected."
return
}
print "WinGet import has successfully imported the apps."
}
# Install apps from Winstall file (the Winstall.txt file must be on the same directory as WinRice).
function Winstall {
$ErrorActionPreference = 'Continue'
if (($installusing -like "1") -or (!($installusing))) {
return
}
space
if (!(Get-Command winget)) {
print "WinGet is not installed. Please install WinGet first before using Winstall."
Start-Process "https://bit.ly/Winstall"
return
}
# Try Winstall.txt
print "Winstall"
$filePath = "$PWD\Winstall.txt"
if (Test-Path -Path $filePath -PathType Leaf) {
# Get each line from the text file and use winget install command on it.
Get-Content 'Winstall.txt' | ForEach-Object
{
$App = $_.Split('=')
print " Installing $App..."
winget install "$App" --source winget --accept-package-agreements --accept-source-agreements --silent | Out-Null
}
print "Winstall has successfully installed the app(s)."
}
else {
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
print "Select Winstall text file from File Picker UI"
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.InitialDirectory = $initialDirectory
$OpenFileDialog.Filter = "Text file (*.txt)| *.txt"
$OpenFileDialog.ShowDialog() | Out-Null
if ($OpenFileDialog.FileName) {
Get-Content $OpenFileDialog.FileName | ForEach-Object
{
$App = $_.Split('=')
print " Installing $App..."
winget install "$App" --source winget --accept-package-agreements --accept-source-agreements --silent | Out-Null
}
print "Winstall has successfully installed the app(s)."