This answer is a PowerShell translation of an excellent answer to this question How can I use JScript to create a shortcut using "Run as administrator", etc.
In short, you need to read the .lnk file as an array of bytes. Find byte 21 (0x15) and change bit 6 (0x20) to 1. This is the RunAsAdministrator flag. Then you write the byte array back to the .lnk file.
In your code, it will look like this:
$WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut("$Home\Desktop\ColorPix.lnk") $Shortcut.TargetPath = "C:\Program Files (x86)\ColorPix\ColorPix.exe" $Shortcut.Save() $bytes = [System.IO.File]::ReadAllBytes("$Home\Desktop\ColorPix.lnk") $bytes[0x15] = $bytes[0x15] -bor 0x20
If someone wants to change something else in the .LNK file, you can refer to the official Microsoft documentation .
Jan Chrbolka Mar 12 '15 at 5:03 2015-03-12 05:03
source share