Old 2nd June 2010, 19:35   #1
akatik
Junior Member
 
Join Date: May 2010
Posts: 19
CreateShortcut to run as administrator

Good day.
I need to create shortcut with advanced property "Run as administrator" set. Help needed.
akatik is offline   Reply With Quote
Old 3rd June 2010, 05:55   #2
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
Quote:
Originally Posted by akatik View Post
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.
MSG is offline   Reply With Quote
Old 3rd June 2010, 07:24   #3
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
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
jpderuiter is offline   Reply With Quote
Old 3rd June 2010, 07:42   #4
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
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.
jpderuiter is offline   Reply With Quote
Old 3rd June 2010, 12:01   #5
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
One could update this plug-in (it would probably have to be me though):
http://nsis.sourceforge.net/ShellLink_plug-in

Stu
Afrow UK is offline   Reply With Quote
Old 3rd June 2010, 16:51   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,321
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

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 3rd June 2010, 19:09   #7
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
I've updated the ShellLink plug-in but currently the Wiki is down.

Stu
Afrow UK is offline   Reply With Quote
Old 4th June 2010, 15:54   #8
akatik
Junior Member
 
Join Date: May 2010
Posts: 19
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.
akatik is offline   Reply With Quote
Old 4th October 2010, 13:35   #9
Mikesch
Junior Member
 
Join Date: Oct 2005
Posts: 19
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.
Mikesch is offline   Reply With Quote
Old 11th February 2011, 11:50   #10
akatik
Junior Member
 
Join Date: May 2010
Posts: 19
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.
akatik is offline   Reply With Quote
Old 11th February 2011, 15:13   #11
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Is the path correct? (SetShellVarContext).

Stu
Afrow UK is offline   Reply With Quote
Old 11th February 2011, 15:25   #12
akatik
Junior Member
 
Join Date: May 2010
Posts: 19
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
akatik is offline   Reply With Quote
Old 11th February 2011, 16:14   #13
akatik
Junior Member
 
Join Date: May 2010
Posts: 19
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".
akatik is offline   Reply With Quote
Old 11th February 2011, 16:15   #14
akatik
Junior Member
 
Join Date: May 2010
Posts: 19
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".
akatik is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump