From 07cac2a88039921573afafd28dc2b22c0f1a468f Mon Sep 17 00:00:00 2001 From: "Mr.k" Date: Fri, 22 Mar 2024 01:58:51 +0300 Subject: [PATCH] MicroWin - Make the New Shortcut have 'Run as administrator' property on (#1659) The added lines of PowerShell Code was taken from public function 'Invoke-WPFShortcut.ps1' under the 'functions/public' Folder. --- functions/private/Invoke-MicroWin-Helper.ps1 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/functions/private/Invoke-MicroWin-Helper.ps1 b/functions/private/Invoke-MicroWin-Helper.ps1 index afcf9080..38544a9f 100644 --- a/functions/private/Invoke-MicroWin-Helper.ps1 +++ b/functions/private/Invoke-MicroWin-Helper.ps1 @@ -637,6 +637,13 @@ function New-FirstRun { $shortcut.Arguments = "-NoProfile -ExecutionPolicy Bypass -Command `"$command`"" # Save the shortcut $shortcut.Save() + + # Make the shortcut have 'Run as administrator' property on + $bytes = [System.IO.File]::ReadAllBytes($shortcutPath) + # 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($shortcutPath, $bytes) + Write-Host "Shortcut created at: $shortcutPath" # # Done create WinUtil shortcut on the desktop @@ -646,4 +653,4 @@ function New-FirstRun { '@ $firstRun | Out-File -FilePath "$env:temp\FirstStartup.ps1" -Force -} \ No newline at end of file +}