mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-12-22 05:51:30 -06:00
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:
parent
caeb89f5d0
commit
9291020d12
@ -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}
|
||||||
|
@ -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"
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user