Python Forum
chnage icon advanced properties !! - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Forum & Off Topic (https://python-forum.io/forum-23.html)
+--- Forum: Bar (https://python-forum.io/forum-27.html)
+--- Thread: chnage icon advanced properties !! (/thread-13147.html)



chnage icon advanced properties !! - evilcode1 - Sep-30-2018

hello all ...
is there anyway to check this box for the icon by python ?

[Image: admin-3.png]
[Image: Cmd-shortcut-run-as-administrator-checkbox.png]


RE: chnage icon advanced properties !! - Larz60+ - Sep-30-2018

And why, do you wish to do this ?????


RE: chnage icon advanced properties !! - evilcode1 - Sep-30-2018

(Sep-30-2018, 11:33 AM)Larz60+ Wrote: And why, do you wish to do this ?????

im coding a tool that create a shortcut for a program that needs administrator privileges....
anyway i found a code that can do that by powershell ...

this is the code :
$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)
Quote: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:


how i can do the same via python ??


RE: chnage icon advanced properties !! - evilcode1 - Oct-01-2018

solved by @Lanting from stackoverflow

code :
filename = r'C:\Users\root\Desktop\qassam.lnk'
with open(filename, "rb") as f2:
  ba = bytearray(f2.read())
  ba[0x15] = ba[0x15] | 0x20
with open(filename, "wb") as f3:
  f3.write(ba)