Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an Admin shortcut with NSIS?

I have an NSIS script that works great, and creates Start menu shortcuts, one of which points to a batch file. The issue is the user will have to right-click and Run as Administrator or it will fail. Is there a way to create the shortcut to Run as Administrator? I am not trying to bypass security, just have it prompt the UAC automatically. The only alternative I could think of is to instruct the user in the batch file, which is tacky IMO. I also thought of searching for Run as Administrator for the batch file itself, but also came up empty.

Here is the Start Menu section of my NSIS installer:

# CREATE SHORTCUTS

!insertmacro MUI_STARTMENU_WRITE_BEGIN MySoftware
    # Create shortcut.
    SetShellVarContext all
    CreateDirectory "$SMPROGRAMS\$SMGroup"
    CreateDirectory "$SMPROGRAMS\$SMGroup\Uninstaller"
    SetOutPath $SMPROGRAMS\$SMGroup
    CreateShortCut "$SMPROGRAMS\$SMGroup\GO.lnk" "$INSTDIR\bin\go.bat"
    CreateShortcut "$SMPROGRAMS\$SMGroup\Uninstaller\Uninstall.lnk" $INSTDIR\Uninstaller.exe

    SectionGetFlags ${SEC_SCHEDULER} $R0 
    IntOp $R0 $R0 & ${SF_SELECTED} 
    IntCmp $R0 ${SF_SELECTED} svc jump1 jump1 
    svc:
    # Create shortcut to Scheduler Service Manager    
    CreateShortCut "$SMPROGRAMS\$SMGroup\Scheduler.lnk" "$INSTDIR\bin\${SVC_MGR_BAT}"
    jump1:
    DetailPrint "Registry Entry: ${REGKEY}\StartMenu : $SMGroup"
    WriteRegStr HKLM "${REGKEY}" StartMenu $SMGroup
!insertmacro MUI_STARTMENU_WRITE_END

Edit: I have checked the CreateShortCut reference, and see no mention of it, but thought there might be some workaround elsewhere in the NSIS script. CreateShortCut NSIS

like image 994
codemonkey Avatar asked Oct 20 '22 12:10

codemonkey


1 Answers

There is a feature request for this here but it has various issues so it has not been implemented:

  • Pre-Vista will show the NT5 RunAs user dialog and you can authenticate with any user there, does not have to be an administrator.
  • What happens when UAC is off?
  • Users could run your batch file manually or create their own shortcuts.

If you still believe this is a good idea you can use this or this...

like image 115
Anders Avatar answered Oct 23 '22 21:10

Anders