|
![]() |
|
Thread Tools | Search this Thread | Display Modes |
![]() |
#1 |
Junior Member
Join Date: Jul 2006
Posts: 31
|
Create a shortcut link which has "Run as administrator" option enabled on Vista
Hi,
During an installation process I need to create a link in the start menu and in case we are on Windows Vista I need this link to have "Run as administrator" option checked. The link is to Windows component (rundll.exe), so I can't achieve this by adding a manifest to an exe. Is this possible with NSIS? Thanks. |
![]() |
![]() |
![]() |
#2 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
Createshortcut does not support this. You could create a small wrapper program with a manifest that exec's rundll32 (you could create the app in nsis even)
IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#3 |
Junior Member
Join Date: Jul 2006
Posts: 31
|
I use rundll.exe to execute the function in my dll. So theoretically I could provide a standalone exe for that. However I put that inside a dll long time ago (before Vista) because I wanted to make things simpler.
Anyway I noticed that on Windows Vista it's the 21st byte of the .lnk file that marks whether the shortcut is launched with elevated rights or not. I could simply modify that byte after .lnk is created (in case we are installing on Vista), but that would be an ugly hack. |
![]() |
![]() |
![]() |
#4 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
http://forums.winamp.com/showthread....hreadid=274267 is about a similar problem, we almost found a solution, but I guess kichik could not get it working in the end, maybe you can...
More of the same: http://forums.winamp.com/showthread....hreadid=277988 http://forums.winamp.com/showthread....hreadid=271953 IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#5 |
Junior Member
Join Date: Jul 2006
Posts: 31
|
I have found an official way to modify link's attributes.
Here is the final function I used (it allows setting attributes only, for clearing attributes it would need to be modified a bit): code: It was beyond me to write it in NSIS script so I put it into the dll, and called via rundll32 upon sucessful install. |
![]() |
![]() |
![]() |
#6 |
Junior Member
Join Date: Jun 2008
Posts: 6
|
OK, I am not sure if there is something is wrong with this method, but I came across this and have not seen a reference to it anywhere on NSIS forum. I think it is way easier than anything else proposed here and seems to work great.
Basically the "Run As Administrator" is simply a registry value stored in "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\layers" , so you can use: code: Obviously replace $MY_SHORCUT_OR_EXE with your executable or shortcut. You can replace HKLM with HKCU for user specific setting instead of all users. I figured I'd share. -HH |
![]() |
![]() |
![]() |
#7 |
Junior Member
Join Date: Sep 2007
Posts: 7
|
Could a senior member/mod etc.. "anders" "joost" "afro" "kichik" "redwine" please confirm the validity of this example:
WriteRegStr HKLM "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\layers" \ "$MY_SHORCUT_OR_EXE" "RUNASADMIN" as the person submitting it has mentioned not knowing whether there is something wrong with it and not finding any other reference to it in the forums , no offence hichhicker but rather safe than sorry as my knowledge of reg writing is not much and this look very useful to me thanks |
![]() |
![]() |
![]() |
#8 | |
Junior Member
Join Date: Jun 2008
Posts: 6
|
Quote:
-HH |
|
![]() |
![]() |
![]() |
#9 |
Junior Member
Join Date: Sep 2007
Posts: 7
|
Thanks , can i ask a few more questions to clear things up?
How would this effect the shortcuts/exe's functionality in xp? you mention $MY_SHORCUT_OR_EXE .. does this mean if you have an exe in programfiles and a shortcut to that on the desktop and start menu you only have to do it once for the exe and all shortcuts to that would be fixed or do i have to do it once for all shortcuts and for the exe .. exact details are crucial to not having to fart arse around guessing how it works when you refer to qoute: "The only issue I still have is the running apps with "run-as-admin" automatically at login." Are you refering to apps launched via a shortcut added to $SMSTARTUP ?? when windows bootsup? This is looking promising so far.. Thanks Hichhiker |
![]() |
![]() |
![]() |
#10 | ||
Junior Member
Join Date: Jun 2008
Posts: 6
|
Quote:
Quote:
code: Which under XP start openvpn-gui when user logs in. Under Vista after reboot I get a message in system tray - "Windows has blocked some startup programs". I tried putting the shortcut in the startup folder - same thing. Looks like you cannot run "run as admin" programs automatically on login - which sucks. -HH |
||
![]() |
![]() |
![]() |
#11 |
Junior Member
Join Date: Mar 2010
Posts: 13
|
Thanks
myself also had a same problem. after doing the above it is working fine in vista. But i can't find layers in specified path in Xp.
HKLM "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\layers" how can i get this one? pls help me. |
![]() |
![]() |
![]() |
#12 |
Major Dude
Join Date: Mar 2003
Posts: 571
|
The ShellLink plug-in can be used to set a shortcut to Run As Administrator:
http://nsis.sourceforge.net/ShellLink_plug-in A forum search found a topic called "CreateShortcut to run as administrator": http://forums.winamp.com/showthread.php?t=319628 |
![]() |
![]() |
![]() |
#13 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
that is the correct path for XP, but why use a ugly hack when you can just use http://nsis.sourceforge.net/IShellLink_Set_RunAs_flag
IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#14 |
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
The ShellLink plug-in also sets the SLDF_RUNAS_USER flag (I added it).
Stu |
![]() |
![]() |
![]() |
#15 |
Junior Member
Join Date: Oct 2010
Posts: 1
|
Please help
---------
EDIT: Sorry, I figure it out. I must be having a slow day to not realize the last 2 lines in the example where explaining how to check if the command was successful. Thank you anyway. --------- Hi, I am still relatively new to NSIS, so I am not sure I understand how to use plugins. I downloaded the ShellLink Plug In from: http://nsis.sourceforge.net/ShellLink_plug-in I unzipped it and copied the ShellLink.dll file to Program Files\NSIS\Plugins. Trying to follow the example on the plugin page, I then modified a part of my script from: ... CreateDirectory "$STARTMENU\Programs\${PRODUCT_PUBLISHER}" CreateShortCut "$STARTMENU\Programs\${PRODUCT_PUBLISHER}\${PRODUCT_NAME}.lnk" "$INSTDIR\${PRODUCT_NAME}.exe" ... to ... CreateDirectory "$STARTMENU\Programs\${PRODUCT_PUBLISHER}" CreateShortCut "$STARTMENU\Programs\${PRODUCT_PUBLISHER}\${PRODUCT_NAME}.lnk" "$INSTDIR\${PRODUCT_NAME}.exe" ShellLink::SetRunAsAdministrator "$STARTMENU\Programs\${PRODUCT_PUBLISHER}\${PRODUCT_NAME}.lnk" Pop $0 $0=0 -no errors $0=-1 -error ... That causes the following error when I try to compile my script: Plugin Command: SetRunAsAdministrator $STARTMENU\Programs\Sharp Software\Auto Sales Manager WPF Server.lnk Pop: $0 Invalid command: $0=0 Error in script "C:\Sharp Software\Auto Sales Manager\trunk\build\scripts\Auto Sales Manager WPF Server.nsi" on line 82 -- aborting creation process Any help getting this to work would be greatly appreciated. Last edited by gpicazo; 1st October 2010 at 21:18. Reason: Solved it |
![]() |
![]() |
![]() |
#16 |
Junior Member
Join Date: Nov 2010
Posts: 1
|
Use only this :
ShellLink::SetRunAsAdministrator "$STARTMENU\Programs\${PRODUCT_PUBLISHER}\${PRODUCT_NAME}.lnk" This command is only if you want to test if command was succesfull (command store variable $0) : Pop $0 $0=0 ; no errors $0=-1 ; error You can use IF command to test this variable (see NSIS doc) |
![]() |
![]() |
![]() |
#17 |
Major Dude
Join Date: Oct 2006
Posts: 1,892
|
|
![]() |
![]() |
![]() |
#18 |
Junior Member
Join Date: Nov 2010
Posts: 8
|
Adding the run as administrator on a shortcut works great. Is it possible to add that property to the actual exe? I have an application that runs automatically when a file with a special extension is opened and I need it to run as admin.
|
![]() |
![]() |
![]() |
#19 |
Major Dude
Join Date: Oct 2006
Posts: 1,892
|
Normally I'd say 'add a manifest', but I have no idea if that works for file associations. I think you can put "runas.exe /user:Administrator yourexe.exe %1" (or something similar) as the opening application, and it will throw a window asking for the admin password. But it's probably much better to make your exe take care of this problem itself: make it so it launches another instance of itself as admin, if it's being run as user.
|
![]() |
![]() |
![]() |
#20 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
Step 1: Add "Vista" manifest to your app requesting admin rights
Step 2: Your app should call IsUserAnAdmin() when it starts up, if false, ShellExecute yourself again with the runas verb IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|