Skip to content

Commit

Permalink
Allow WinDebloatTools to run asking for admin perms +
Browse files Browse the repository at this point in the history
+ Run Windows Terminal or PowerShell depending on winget.
- If script is in the wrong folder, it'll be able to detect and correct it.
  • Loading branch information
LeDragoX committed Oct 10, 2023
1 parent 26c2e7f commit 7e9743e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions WinDebloatTools.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Learned from: https://docs.microsoft.com/en-us/powershell/scripting/samples/creating-a-custom-input-box?view=powershell-7.1
# Learned from: https://docs.microsoft.com/en-us/powershell/scripting/samples/creating-a-custom-input-box?view=powershell-7.1
# Adapted majorly from https://github.com/ChrisTitusTech/win10script and https://github.com/Sycnex/Windows10Debloater
# Take Ownership tweak from: https://www.howtogeek.com/howto/windows-vista/add-take-ownership-to-explorer-right-click-menu-in-vista/

Expand Down Expand Up @@ -41,6 +41,11 @@ function Main() {
Import-Module -DisableNameChecking "$PSScriptRoot\src\utils\Individual-Tweaks.psm1" -Force
Import-Module -DisableNameChecking "$PSScriptRoot\src\utils\Install-Individual-System-Apps.psm1" -Force

If ("$pwd" -notlike "$PSScriptRoot") {
Write-Host "Wrong location detected, changing to script folder!" -BackgroundColor Yellow
Set-Location -Path "$PSScriptRoot"
}

Set-ConsoleStyle
$CurrentFileName = (Split-Path -Path $PSCommandPath -Leaf).Split('.')[0]
$CurrentFileLastModified = (Get-Item "$(Split-Path -Path $PSCommandPath -Leaf)").LastWriteTimeUtc | Get-Date -Format "yyyy-MM-dd"
Expand Down Expand Up @@ -103,7 +108,14 @@ function Open-DebloatScript {

function Request-AdminPrivilege() {
# Used from https://stackoverflow.com/a/31602095 because it preserves the working directory!
If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Try {
winget --version
Start-Process -Verb RunAs -FilePath "wt.exe" -ArgumentList "--startingDirectory `"$PSScriptRoot`" --profile `"Windows PowerShell`"", "cmd /c powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`""; taskkill.exe /f /im $PID; exit
} Catch {
Start-Process -Verb RunAs -FilePath powershell.exe -ArgumentList "-NoProfile", "-ExecutionPolicy Bypass", "-File `"$PSCommandPath`""; exit
}
}
}

function Show-GUI() {
Expand Down

0 comments on commit 7e9743e

Please sign in to comment.