Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Make shortcut "Run as Admin"
#1
Hi Gintaras,
I know how to add the "run as admin" argument to a run command but how do I add that to a shortcut link e.g. using CreateShortcut

What I mean is that in Windows you can right click on a shortcut and it gives you the "run as admin" option but don't know how to set that up programatically.

Alternatively, I could just make the shortcut go to a little executable that run's the real target with the run as admin flag but a direct way would be more elegant.


Code:
Copy      Help
run "$program files$\RadFusion\SampleApp.exe" "" "" "" 0x10000


Thanks,
Stuart
#2
Macro create 'run as admin' shortcut
Code:
Copy      Help
str lnkFile.expandpath("$desktop$\notepad.lnk")
str targetFile.expandpath("$system$\notepad.exe")

;create shortcut
if(!CreateShortcut(lnkFile targetFile)) ret

;set 'run as admin'
BSTR blf=lnkFile
IShellLinkW sl._create(CLSID_ShellLink)
IPersistFile pf=+sl
pf.Load(blf STGM_READ|STGM_WRITE)
IShellLinkDataList dl=+sl
dl.GetFlags(&_i)
if(_i&SLDF_RUNAS_USER) ret
dl.SetFlags(_i|SLDF_RUNAS_USER)
pf.Save(blf 1)

;;note: it sets 'run as admin' only for the shortcut, not for the exe, therefore the checkbox in shortcut Properties is not checked, and no shield overlay on icon, and if you double click exe or other shortcut to it, it will not run as admin
#3
thanks so much!!!
Stuart


Forum Jump:


Users browsing this thread: 1 Guest(s)