-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshortcut.ps1
33 lines (25 loc) · 991 Bytes
/
shortcut.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function Set-ShortcutRunAsAdministrator {
[CmdletBinding(SupportsShouldProcess)]
param (
[Parameter(Mandatory = $true)]
[Alias("Path")]
[string] $ShortcutPath
)
$bytes = [System.IO.File]::ReadAllBytes($ShortcutPath)
$bytes[0x15] = $bytes[0x15] -bor 0x20 #set byte 21 (0x15) bit 6 (0x20) ON
if ($PSCmdlet.ShouldProcess($ShortcutPath, "Set 'Run as administrator' flag")) {
[System.IO.File]::WriteAllBytes($ShortcutPath, $bytes)
}
<#
.SYNOPSIS
Modifies a shortcut to run as administrator.
.DESCRIPTION
Sets the "Run as administrator" flag on the specified shortcut.
.PARAMETER ShortcutPath
The path to the shortcut to set the "Run as administrator" flag on.
.EXAMPLE
Set-ShortcutRunAsAdministrator -ShortcutPath "C:\Users\UserName\Desktop\MyShortcut.lnk"
.NOTES
This function is based on the answer at https://stackoverflow.com/a/29002207/2562544.
#>
}