0

I have been assigned the job of automating a long list of tasks for developers to load into Intune. One of the tasks is to set the Run As Administrator feature to Visual Studio with a script. I know you can right-click on the exe, go to properties > Advanced and set that setting, but I'm struggling to find a scriptable way to do that. Any suggestions would be appreciated.

Edit: This to update the shortcut to send the command to run as administrator.

4
  • Remember the SO rules: Provide MRE --- How to ask --- Don't ask --- Proper Topic --- Why not upload images of code/errors? --- format your post properly --- Tour Commented Nov 2, 2022 at 0:11
  • What did you search for? What have you tried? What were the results/errors? Show some stuff. Also of note, this is not the first time this question has been asked. Several articles exist on the topic. Lastly, it's a choice but, as an operational risk and end-user delivery thing, developers should not be running/developing as admin anyway. They should be doing that as a regular user, and only elevate to admin for dev admin-required tasks. Commented Nov 2, 2022 at 1:01
  • You can just create a reference machine, set whatever you want and export /backup the settings -- shortcuts, and import/install them to a new machine. Just as you would when creating a normal Gold OS reference image. Commented Nov 2, 2022 at 1:02
  • stackoverflow.com/questions/28997799/… and here social.technet.microsoft.com/Forums/en-US/… Commented Nov 2, 2022 at 4:43

1 Answer 1

1

The shell-friendly way to create shortcut files (*.lnk) unfortunately does not provide a way to mark a shortcut file as needing to run with elevation (as administrator).

To do so, you have two options:

  • A quick-and-dirty solution based on raw byte manipulation of a .lnk file.

    • The caveat is that such an approach may break in a future Windows version, should the binary file format of shortcut file changes. See below.
  • A proper solution via the appropriate COM interfaces, which are not script-friendly, however.


Quick-and-dirty solution, effective as of Windows 10, gratefully adapted from this answer:

# Get the *full path* of the target shortcut file (*.lnk),
# using sample path ~/Desktop/test.lnk here.
$shortcutFile = Convert-Path -LiteralPath (Get-Item ~/Desktop/test.lnk)

# Read the shortcut file's raw byte contents.
$bytes = [System.IO.File]::ReadAllBytes($shortcutFile)

# Set the relevant byte to mark the shortcut as needing to
# run with elevation.
$bytes[21] = 34

# Save the modified byte array back to the original file.
[System.IO.File]::WriteAllBytes($shortCutLocation, $bytes)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.