mirror of
https://github.com/Sycnex/Windows10Debloater.git
synced 2025-03-13 18:15:30 +00:00
Added popup box for admin rights or not
When you run the script now, there is a choice if you want to run it as an Administrator or not, per issue #106
This commit is contained in:
parent
e786feb707
commit
4109280391
@ -1,8 +1,30 @@
|
||||
#This will self elevate the script so with a UAC prompt since this script needs to be run as an Administrator in order to function properly.
|
||||
|
||||
$ErrorActionPreference = 'silentlycontinue'
|
||||
|
||||
$Button = [Windows.MessageBoxButton]::YesNoCancel
|
||||
$ErrorIco = [Windows.MessageBoxImage]::Error
|
||||
$Ask = 'Do you want to run this as an Administrator?
|
||||
|
||||
Select "Yes" to Run as an Administrator
|
||||
|
||||
Select "No" to not run this as an Administrator
|
||||
|
||||
Select "Cancel" to stop the script.'
|
||||
|
||||
If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')) {
|
||||
$Prompt = [Windows.MessageBox]::Show($Ask, "Run as an Administrator or not?", $Button, $ErrorIco)
|
||||
Switch ($Prompt) {
|
||||
#This will debloat Windows 10
|
||||
Yes {
|
||||
Write-Host "You didn't run this script as an Administrator. This script will self elevate to run as an Administrator and continue."
|
||||
Start-Process powershell.exe -ArgumentList ("-NoProfile -ExecutionPolicy Bypass -File `"{0}`"" -f $PSCommandPath) -Verb RunAs
|
||||
Exit
|
||||
}
|
||||
No {
|
||||
Break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Unnecessary Windows 10 AppX apps that will be removed by the blacklist.
|
||||
@ -95,12 +117,13 @@ $global:WhiteListedApps = @(
|
||||
)
|
||||
|
||||
#NonRemovable Apps that where getting attempted and the system would reject the uninstall, speeds up debloat and prevents 'initalizing' overlay when removing apps
|
||||
$NonRemovables = Get-AppxPackage -AllUsers | Where-Object {$_.NonRemovable -eq $true} | foreach{$_.Name}
|
||||
$NonRemovables += Get-AppxPackage | Where-Object {$_.NonRemovable -eq $true} | foreach{$_.Name}
|
||||
$NonRemovables += Get-AppxProvisionedPackage -Online | Where-Object {$_.NonRemovable -eq $true} | foreach{$_.DisplayName}
|
||||
$NonRemovables = Get-AppxPackage -AllUsers | Where-Object { $_.NonRemovable -eq $true } | foreach { $_.Name }
|
||||
$NonRemovables += Get-AppxPackage | Where-Object { $_.NonRemovable -eq $true } | foreach { $_.Name }
|
||||
$NonRemovables += Get-AppxProvisionedPackage -Online | Where-Object { $_.NonRemovable -eq $true } | foreach { $_.DisplayName }
|
||||
$NonRemovables = $NonRemovables | Sort-Object -unique
|
||||
|
||||
if ($NonRemovables -eq $null ) { # the .NonRemovable property doesn't exist until version 18xx. Use a hard-coded list instead.
|
||||
if ($NonRemovables -eq $null ) {
|
||||
# the .NonRemovable property doesn't exist until version 18xx. Use a hard-coded list instead.
|
||||
#WARNING: only use exact names here - no short names or wildcards
|
||||
$NonRemovables = @(
|
||||
"1527c705-839a-4832-9118-54d4Bd6a0c89"
|
||||
@ -157,7 +180,7 @@ Function dotInclude() {
|
||||
if ( $PSScriptRoot -eq $null -and $psISE) {
|
||||
$scriptPath = (Split-Path -Path $psISE.CurrentFile.FullPath)
|
||||
}
|
||||
if ( test-path $scriptPath\$includeFile ){
|
||||
if ( test-path $scriptPath\$includeFile ) {
|
||||
# import and immediately execute the requested file
|
||||
. $scriptPath\$includeFile
|
||||
}
|
||||
@ -390,17 +413,17 @@ $CustomizeBlacklists.Add_Click( {
|
||||
[string] $notes
|
||||
)
|
||||
|
||||
$label=New-Object system.Windows.Forms.Label
|
||||
$label.Location = New-Object System.Drawing.Point(2,(30+$position*16))
|
||||
$label = New-Object system.Windows.Forms.Label
|
||||
$label.Location = New-Object System.Drawing.Point(2, (30 + $position * 16))
|
||||
$label.Text = $notes
|
||||
$label.width = 300
|
||||
$label.height= 16
|
||||
$label.height = 16
|
||||
$Label.TextAlign = [System.Drawing.ContentAlignment]::TopRight
|
||||
$CustomizeForm.controls.Add($label)
|
||||
|
||||
$Checkbox = New-Object system.Windows.Forms.CheckBox
|
||||
$Checkbox.text = $appName
|
||||
$Checkbox.location = New-Object System.Drawing.Point(320,(30+$position*16))
|
||||
$Checkbox.location = New-Object System.Drawing.Point(320, (30 + $position * 16))
|
||||
$Checkbox.Autosize = 1;
|
||||
$Checkbox.Checked = $checked
|
||||
$Checkbox.Enabled = $enabled
|
||||
@ -415,68 +438,68 @@ $CustomizeBlacklists.Add_Click( {
|
||||
|
||||
foreach ($item in $NonRemovables) {
|
||||
$string = ""
|
||||
if ( $null -notmatch $global:BloatwareRegex -and $item -cmatch $global:BloatwareRegex ) {$string += " ConflictBlacklist "}
|
||||
if ( $null -notmatch $global:WhiteListedAppsRegex -and $item -cmatch $global:WhiteListedAppsRegex ) {$string += " ConflictWhitelist" }
|
||||
if ( $null -notmatch $Installed -and $Installed -cmatch $item){ $string += "Installed"}
|
||||
if ( $null -notmatch $AllUsers -and $AllUsers -cmatch $item) {$string += " AllUsers"}
|
||||
if ( $null -notmatch $Online -and $Online -cmatch $item) {$string += " Online"}
|
||||
if ( $null -notmatch $global:BloatwareRegex -and $item -cmatch $global:BloatwareRegex ) { $string += " ConflictBlacklist " }
|
||||
if ( $null -notmatch $global:WhiteListedAppsRegex -and $item -cmatch $global:WhiteListedAppsRegex ) { $string += " ConflictWhitelist" }
|
||||
if ( $null -notmatch $Installed -and $Installed -cmatch $item) { $string += "Installed" }
|
||||
if ( $null -notmatch $AllUsers -and $AllUsers -cmatch $item) { $string += " AllUsers" }
|
||||
if ( $null -notmatch $Online -and $Online -cmatch $item) { $string += " Online" }
|
||||
$string += " NONREMOVABLE"
|
||||
AddAppToCustomizeForm $checkboxCounter $item $false $false $string
|
||||
++$checkboxCounter
|
||||
}
|
||||
foreach ( $item in $global:WhiteListedApps ) {
|
||||
$string = ""
|
||||
if ( $null -notmatch $NonRemovables -and $NonRemovables -cmatch $item ) {$string += " Conflict NonRemovables "}
|
||||
if ( $null -notmatch $global:BloatwareRegex -and $item -cmatch $global:BloatwareRegex ) {$string += " ConflictBlacklist "}
|
||||
if ( $null -notmatch $Installed -and $Installed -cmatch $item){ $string += "Installed"}
|
||||
if ( $null -notmatch $AllUsers -and $AllUsers -cmatch $item) {$string += " AllUsers"}
|
||||
if ( $null -notmatch $Online -and $Online -cmatch $item) {$string += " Online"}
|
||||
if ( $null -notmatch $NonRemovables -and $NonRemovables -cmatch $item ) { $string += " Conflict NonRemovables " }
|
||||
if ( $null -notmatch $global:BloatwareRegex -and $item -cmatch $global:BloatwareRegex ) { $string += " ConflictBlacklist " }
|
||||
if ( $null -notmatch $Installed -and $Installed -cmatch $item) { $string += "Installed" }
|
||||
if ( $null -notmatch $AllUsers -and $AllUsers -cmatch $item) { $string += " AllUsers" }
|
||||
if ( $null -notmatch $Online -and $Online -cmatch $item) { $string += " Online" }
|
||||
AddAppToCustomizeForm $checkboxCounter $item $true $false $string
|
||||
++$checkboxCounter
|
||||
}
|
||||
foreach ( $item in $global:Bloatware ) {
|
||||
$string = ""
|
||||
if ( $null -notmatch $NonRemovables -and $NonRemovables -cmatch $item ) {$string += " Conflict NonRemovables "}
|
||||
if ( $null -notmatch $global:WhiteListedAppsRegex -and $item -cmatch $global:WhiteListedAppsRegex ) {$string += " Conflict Whitelist "}
|
||||
if ( $null -notmatch $Installed -and $Installed -cmatch $item){ $string += "Installed"}
|
||||
if ( $null -notmatch $AllUsers -and $AllUsers -cmatch $item) {$string += " AllUsers"}
|
||||
if ( $null -notmatch $Online -and $Online -cmatch $item) {$string += " Online"}
|
||||
if ( $null -notmatch $NonRemovables -and $NonRemovables -cmatch $item ) { $string += " Conflict NonRemovables " }
|
||||
if ( $null -notmatch $global:WhiteListedAppsRegex -and $item -cmatch $global:WhiteListedAppsRegex ) { $string += " Conflict Whitelist " }
|
||||
if ( $null -notmatch $Installed -and $Installed -cmatch $item) { $string += "Installed" }
|
||||
if ( $null -notmatch $AllUsers -and $AllUsers -cmatch $item) { $string += " AllUsers" }
|
||||
if ( $null -notmatch $Online -and $Online -cmatch $item) { $string += " Online" }
|
||||
AddAppToCustomizeForm $checkboxCounter $item $true $true $string
|
||||
++$checkboxCounter
|
||||
}
|
||||
foreach ( $item in $AllUsers ) {
|
||||
$string = "NEW AllUsers"
|
||||
if ( $null -notmatch $NonRemovables -and $NonRemovables -cmatch $item ) {continue}
|
||||
if ( $null -notmatch $global:WhiteListedAppsRegex -and $item -cmatch $global:WhiteListedAppsRegex ) {continue}
|
||||
if ( $null -notmatch $global:BloatwareRegex -and $item -cmatch $global:BloatwareRegex ) {continue}
|
||||
if ( $null -notmatch $Installed -and $Installed -cmatch $item){ $string += " Installed"}
|
||||
if ( $null -notmatch $Online -and $Online -cmatch $item) {$string += " Online"}
|
||||
if ( $null -notmatch $NonRemovables -and $NonRemovables -cmatch $item ) { continue }
|
||||
if ( $null -notmatch $global:WhiteListedAppsRegex -and $item -cmatch $global:WhiteListedAppsRegex ) { continue }
|
||||
if ( $null -notmatch $global:BloatwareRegex -and $item -cmatch $global:BloatwareRegex ) { continue }
|
||||
if ( $null -notmatch $Installed -and $Installed -cmatch $item) { $string += " Installed" }
|
||||
if ( $null -notmatch $Online -and $Online -cmatch $item) { $string += " Online" }
|
||||
AddAppToCustomizeForm $checkboxCounter $item $true $true $string
|
||||
++$checkboxCounter
|
||||
}
|
||||
foreach ( $item in $Installed ) {
|
||||
$string = "NEW Installed"
|
||||
if ( $null -notmatch $NonRemovables -and $NonRemovables -cmatch $item ) {continue}
|
||||
if ( $null -notmatch $global:WhiteListedAppsRegex -and $item -cmatch $global:WhiteListedAppsRegex ) {continue}
|
||||
if ( $null -notmatch $global:BloatwareRegex -and $item -cmatch $global:BloatwareRegex ) {continue}
|
||||
if ( $null -notmatch $AllUsers -and $AllUsers -cmatch $item) {continue}
|
||||
if ( $null -notmatch $Online -and $Online -cmatch $item) {$string += " Online"}
|
||||
if ( $null -notmatch $NonRemovables -and $NonRemovables -cmatch $item ) { continue }
|
||||
if ( $null -notmatch $global:WhiteListedAppsRegex -and $item -cmatch $global:WhiteListedAppsRegex ) { continue }
|
||||
if ( $null -notmatch $global:BloatwareRegex -and $item -cmatch $global:BloatwareRegex ) { continue }
|
||||
if ( $null -notmatch $AllUsers -and $AllUsers -cmatch $item) { continue }
|
||||
if ( $null -notmatch $Online -and $Online -cmatch $item) { $string += " Online" }
|
||||
AddAppToCustomizeForm $checkboxCounter $item $true $true $string
|
||||
++$checkboxCounter
|
||||
}
|
||||
foreach ( $item in $Online ) {
|
||||
$string = "NEW Online "
|
||||
if ( $null -notmatch $NonRemovables -and $NonRemovables -cmatch $item ) {continue}
|
||||
if ( $null -notmatch $global:WhiteListedAppsRegex -and $item -cmatch $global:WhiteListedAppsRegex ) {continue}
|
||||
if ( $null -notmatch $global:BloatwareRegex -and $item -cmatch $global:BloatwareRegex ) {continue}
|
||||
if ( $null -notmatch $Installed -and $Installed -cmatch $item){ continue}
|
||||
if ( $null -notmatch $AllUsers -and $AllUsers -cmatch $item) { continue}
|
||||
if ( $null -notmatch $NonRemovables -and $NonRemovables -cmatch $item ) { continue }
|
||||
if ( $null -notmatch $global:WhiteListedAppsRegex -and $item -cmatch $global:WhiteListedAppsRegex ) { continue }
|
||||
if ( $null -notmatch $global:BloatwareRegex -and $item -cmatch $global:BloatwareRegex ) { continue }
|
||||
if ( $null -notmatch $Installed -and $Installed -cmatch $item) { continue }
|
||||
if ( $null -notmatch $AllUsers -and $AllUsers -cmatch $item) { continue }
|
||||
AddAppToCustomizeForm $checkboxCounter $item $true $true $string
|
||||
++$checkboxCounter
|
||||
}
|
||||
[void]$CustomizeForm.ShowDialog()
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
$RemoveBlacklist.Add_Click( {
|
||||
@ -525,11 +548,11 @@ $RemoveAllBloatware.Add_Click( {
|
||||
|
||||
Param([switch]$Debloat)
|
||||
|
||||
If (Get-Service dmwappushservice | Where-Object {$_.StartType -eq "Disabled"}) {
|
||||
If (Get-Service dmwappushservice | Where-Object { $_.StartType -eq "Disabled" }) {
|
||||
Set-Service dmwappushservice -StartupType Automatic
|
||||
}
|
||||
|
||||
If (Get-Service dmwappushservice | Where-Object {$_.Status -eq "Stopped"}) {
|
||||
If (Get-Service dmwappushservice | Where-Object { $_.Status -eq "Stopped" }) {
|
||||
Start-Service dmwappushservice
|
||||
}
|
||||
}
|
||||
@ -539,7 +562,7 @@ $RemoveAllBloatware.Add_Click( {
|
||||
Get-AppxPackage | Where { !($_.Name -cmatch $global:WhiteListedAppsRegex) -and !($NonRemovables -cmatch $_.Name) } | Remove-AppxPackage
|
||||
Get-AppxProvisionedPackage -Online | Where { !($_.DisplayName -cmatch $global:WhiteListedAppsRegex) -and !($NonRemovables -cmatch $_.DisplayName) } | Remove-AppxProvisionedPackage -Online
|
||||
Get-AppxPackage -AllUsers | Where { !($_.Name -cmatch $global:WhiteListedAppsRegex) -and !($NonRemovables -cmatch $_.Name) } | Remove-AppxPackage
|
||||
}
|
||||
}
|
||||
|
||||
#Creates a PSDrive to be able to access the 'HKCR' tree
|
||||
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
|
||||
@ -695,9 +718,9 @@ $RemoveAllBloatware.Add_Click( {
|
||||
(New-Object -Com Shell.Application).
|
||||
NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').
|
||||
Items() |
|
||||
%{ $_.Verbs() } |
|
||||
?{$_.Name -match 'Un.*pin from Start'} |
|
||||
%{$_.DoIt()}
|
||||
% { $_.Verbs() } |
|
||||
? { $_.Name -match 'Un.*pin from Start' } |
|
||||
% { $_.DoIt() }
|
||||
}
|
||||
|
||||
Function Remove3dObjects {
|
||||
@ -711,25 +734,25 @@ $RemoveAllBloatware.Add_Click( {
|
||||
If (Test-Path $Objects64) {
|
||||
Remove-Item $Objects64 -Recurse
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Function CheckDMWService {
|
||||
|
||||
Param([switch]$Debloat)
|
||||
|
||||
If (Get-Service dmwappushservice | Where-Object {$_.StartType -eq "Disabled"}) {
|
||||
If (Get-Service dmwappushservice | Where-Object { $_.StartType -eq "Disabled" }) {
|
||||
Set-Service dmwappushservice -StartupType Automatic
|
||||
}
|
||||
|
||||
If (Get-Service dmwappushservice | Where-Object {$_.Status -eq "Stopped"}) {
|
||||
If (Get-Service dmwappushservice | Where-Object { $_.Status -eq "Stopped" }) {
|
||||
Start-Service dmwappushservice
|
||||
}
|
||||
}
|
||||
|
||||
Function CheckInstallService {
|
||||
|
||||
If (Get-Service InstallService | Where-Object {$_.Status -eq "Stopped"}) {
|
||||
If (Get-Service InstallService | Where-Object { $_.Status -eq "Stopped" }) {
|
||||
Start-Service InstallService
|
||||
Set-Service InstallService -StartupType Automatic
|
||||
}
|
||||
@ -758,7 +781,7 @@ $RevertChange.Add_Click( {
|
||||
#This function will revert the changes you made when running the Start-Debloat function.
|
||||
|
||||
#This line reinstalls all of the bloatware that was removed
|
||||
Get-AppxPackage -AllUsers | ForEach {Add-AppxPackage -Verbose -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
|
||||
Get-AppxPackage -AllUsers | ForEach { Add-AppxPackage -Verbose -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml" }
|
||||
|
||||
#Tells Windows to enable your advertising information.
|
||||
Write-Host "Re-enabling key to show advertisement information"
|
||||
@ -1162,9 +1185,9 @@ $UnpinStartMenuTiles.Add_Click( {
|
||||
(New-Object -Com Shell.Application).
|
||||
NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').
|
||||
Items() |
|
||||
%{ $_.Verbs() } |
|
||||
?{$_.Name -match 'Un.*pin from Start'} |
|
||||
%{$_.DoIt()}
|
||||
% { $_.Verbs() } |
|
||||
? { $_.Name -match 'Un.*pin from Start' } |
|
||||
% { $_.DoIt() }
|
||||
})
|
||||
|
||||
$RemoveOnedrive.Add_Click( {
|
||||
@ -1258,7 +1281,7 @@ $EnableDarkMode.Add_Click( {
|
||||
Set-ItemProperty $Theme AppsUseLightTheme -Value 0
|
||||
Start-Sleep 1
|
||||
Write-Host "Enabled"
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
$DisableDarkMode.Add_Click( {
|
||||
@ -1267,7 +1290,7 @@ $DisableDarkMode.Add_Click( {
|
||||
Set-ItemProperty $Theme AppsUseLightTheme -Value 1
|
||||
Start-Sleep 1
|
||||
Write-Host "Disabled"
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
[void]$Form.ShowDialog()
|
||||
|
Loading…
Reference in New Issue
Block a user