Archive: CreateShortcut to run as administrator


CreateShortcut to run as administrator
Good day.
I need to create shortcut with advanced property "Run as administrator" set. Help needed.


Originally posted by akatik
Good day.
I need to create shortcut with advanced property "Run as administrator" set. Help needed.
I don't know if this is possible in a shortcut, but I think you could add a manifest to the exe with admin as requested execution level.

Well, it is possible, but a pain to write in a script.
Maybe a plugin is easier:
http://social.msdn.microsoft.com/For...9-2e3df3668989


You can also try to add a REG_SZ key named <Full_Path _To_My_Application.exe> with a value of "RUNASADMIN" to the registry at HKCU\SOFTWARE\Microsoft\Windows_NT\CurrentVersion\AppCompatFlags\Layers.
(Source: http://www.techtalkz.com/windows-dep...all-users.html)
I don't have Vista, so I can't test this for you.


One could update this plug-in (it would probably have to be me though):
http://nsis.sourceforge.net/ShellLink_plug-in

Stu


People keep asking this over and over, but it seems to me that you probably have other problems if you need this property set on your shortcuts (What if the user runs the app directly?) Anyways, here is some code: http://nsis.sourceforge.net/IShellLink_Set_RunAs_flag


I've updated the ShellLink plug-in but currently the Wiki is down.

Stu


MSG Elevating application is not the decision I need. Simple users should have the ability to run it.
Anders, I understand, that writing programs that require administrative rights is not good. But my program is meant for system administrators. There will be two shortcuts - for simple users with restricted possibilities - and for admins, full functioning.
Thank you, Afrow UK, it works fine.
Thanks for you all a lot. There are several topics on this issue on the forum. But only here is the helpful solution.


Hello Afrow UK!

Many thanks for your great solution. This works fine for my application.

Because of the many threads about this problem perhaps it could become part of the next NSIS setup.


I have a problem - I set flag "Run as Administrator" using this code: http://nsis.sourceforge.net/IShellLink_Set_RunAs_flag
If my shortcut is placed in All users Start menu, then it works great.
But in Start menu of current user - no flag is set.


Is the path correct? (SetShellVarContext).

Stu


Yes, path is correct. The code is:

CreateShortcut "$SMPROGRAMS\wtc\${wtcTxt}-Administrator.lnk" "$INSTDIR\Bin\win32.exe"
push "$SMPROGRAMS\wtc\${wtcTxt}-Administrator.lnk"
call ShellLinkSetRunAs
pop $0

As far as I understood this function returned not 0:
System::Call "$2->5(w '$9',i 0)i.r0" ;Load


Afrow UK, you were right.
"Windows Vista and Windows 7 automatically identifies installer executables, including NSIS installers, and asks the user permission to run them with elevated privileges. Automatic detection, however, comes with the price of automatic backward compatibility tricks. One of which is automatic relocation of shortcuts created in the Start Menu to All Users' Start Menu."

I hate Microsoft :( It placeŠ² my shortcut to All users start menu and even didn't say "Meow".


Afrow UK, you were right.
"Windows Vista and Windows 7 automatically identifies installer executables, including NSIS installers, and asks the user permission to run them with elevated privileges. Automatic detection, however, comes with the price of automatic backward compatibility tricks. One of which is automatic relocation of shortcuts created in the Start Menu to All Users' Start Menu."

I hate Microsoft :( It placeŠ² my shortcut to All users start menu and even didn't say "Meow".