Creating software abbreviations using C # and setting the property "Run as administrator"

I already know how to programmatically create shortcuts from my C # applications using IWshRuntimeLibraryand WshShellClass. Or I could use IShellLink.

Now, if the user PC is running Windows Vista or Windows 7, I would also like to be able to set the "Run as administrator" property for this shortcut programmatically.

Is it possible? If so, how?

alt text

+3
source share
3 answers

While Doug's answer is the correct solution to this problem, this is not the answer to this specific question ...

.lnk, COM- IShellLinkDataList. ++

+3

, . , .

!

+3

PowerShell, , #.

, activtae:

# Find the missing admin byte (use this code, when changing the link):
$adminon = [System.IO.File]::ReadAllBytes($shortCutLocation)
$adminof = [System.IO.File]::ReadAllBytes($shortCutLocation)
for ($i = 0; $i -lt $adminon.Count; $i++) { 
    if ($adminon[$i] -ne $adminof[$i]) { 
        Write-Host Location: $i Value: $($adminon[$i])  
    } 
}

№ 21 34. , script I:

# Turning on the byte of "Run as Admin"
$lnkBytes = [System.IO.File]::ReadAllBytes($shortCutLocation)
$lnkBytes[21] = 34
[System.IO.File]::WriteAllBytes($shortCutLocation, $lnkBytes)
+3

Source: https://habr.com/ru/post/1771780/


All Articles