Add 'Run as administrator' to 'Invoke-WPFShortcut' Function and Use it in 'Invoke-WPFButton' (#1625)

The full details on implementation is found in the commit changes, as well as documentation in 'Invoke-WPFShortcut.ps1' file.
This commit is contained in:
Mr.k 2024-02-22 04:12:44 +03:00 committed by GitHub
parent caeb89f5d0
commit 9291020d12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 3 deletions

View File

@ -47,7 +47,7 @@ function Invoke-WPFButton {
"WPFFixesNetwork" {Invoke-WPFFixesNetwork} "WPFFixesNetwork" {Invoke-WPFFixesNetwork}
"WPFUpdatesdisable" {Invoke-WPFUpdatesdisable} "WPFUpdatesdisable" {Invoke-WPFUpdatesdisable}
"WPFUpdatessecurity" {Invoke-WPFUpdatessecurity} "WPFUpdatessecurity" {Invoke-WPFUpdatessecurity}
"WPFWinUtilShortcut" {Invoke-WPFShortcut -ShortcutToAdd "WinUtil"} "WPFWinUtilShortcut" {Invoke-WPFShortcut -ShortcutToAdd "WinUtil" -RunAsAdmin $true}
"WPFGetInstalled" {Invoke-WPFGetInstalled -CheckBox "winget"} "WPFGetInstalled" {Invoke-WPFGetInstalled -CheckBox "winget"}
"WPFGetInstalledTweaks" {Invoke-WPFGetInstalled -CheckBox "tweaks"} "WPFGetInstalledTweaks" {Invoke-WPFGetInstalled -CheckBox "tweaks"}
"WPFGetIso" {Invoke-WPFGetIso} "WPFGetIso" {Invoke-WPFGetIso}

View File

@ -8,8 +8,14 @@ function Invoke-WPFShortcut {
.PARAMETER ShortcutToAdd .PARAMETER ShortcutToAdd
The name of the shortcut to add The name of the shortcut to add
.PARAMETER RunAsAdmin
A boolean value to make 'Run as administrator' property on (true) or off (false), defaults to off
#> #>
param($ShortcutToAdd) param(
$ShortcutToAdd,
[bool]$RunAsAdmin = $false
)
$iconPath = $null $iconPath = $null
Switch ($ShortcutToAdd) { Switch ($ShortcutToAdd) {
@ -42,5 +48,12 @@ function Invoke-WPFShortcut {
} }
$Shortcut.Save() $Shortcut.Save()
Write-Host "Shortcut for $ShortcutToAdd has been saved to $($FileBrowser.FileName)" if ($RunAsAdmin -eq $true) {
$bytes = [System.IO.File]::ReadAllBytes($FileBrowser.FileName)
# Set byte value at position 0x15 in hex, or 21 in decimal, from the value 0x00 to 0x20 in hex
$bytes[0x15] = $bytes[0x15] -bor 0x20
[System.IO.File]::WriteAllBytes($FileBrowser.FileName, $bytes)
}
Write-Host "Shortcut for $ShortcutToAdd has been saved to $($FileBrowser.FileName) with 'Run as administrator' set to $RunAsAdmin"
} }