Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 663 Vote(s) - 3.44 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to create a Run As Administrator shortcut using Powershell

#1
In my PowerShell script, I create a shortcut to a .exe (using something similar to the answer from [this question][1]):

$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\ColorPix.lnk")
$Shortcut.TargetPath = "C:\Program Files (x86)\ColorPix\ColorPix.exe"
$Shortcut.Save()

Now, when I create the shortcut, how do I add to the script to make it default to running as Administrator?

[1]:

[To see links please register here]

"this question"
Reply

#2
This answer is a PowerShell translation of an excellent answer to this question

[To see links please register here]

.

In short, you need to read the .lnk file in as an array of bytes. Locate byte 21 (0x15) and change bit 6 (0x20) to 1. This is the RunAsAdministrator flag. Then you write you byte array back into the .lnk file.

In your code this would 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 #set byte 21 (0x15) bit 6 (0x20) ON
[System.IO.File]::WriteAllBytes("$Home\Desktop\ColorPix.lnk", $bytes)

If anybody want to change something else in a `.LNK` file you can refer to [official Microsoft documentation][1].


[1]:

[To see links please register here]

Reply

#3
You can use the -Elevate true switch for this:

CreateShortcut -name "myApp" -Target
"${env:ProgramFiles}\mApp\myApp.exe" -OutputDirectory
"C:\Users\Public\Desktop" -Elevated True
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through