简体   繁体   中英

How to copy and install a dll into assembly folder using NSIS on an Windows OS with elevated UAC

I am building an application setup where the installation involves copying and registering Microsoft.VisualBasic.PowerPacks.Vs into the Windows assembly folder. This process sometimes fails on a Windows 7 system where the UAC is active.Currently, i use the following script in a section:

SetOutPath $INSTDIR\bin
File "..\MyFolder\systemfiles\Microsoft.VisualBasic.PowerPacks.Vs.dll
ExecWait '"$R0\RegAsm.exe" Microsoft.VisualBasic.PowerPacks.Vs.dll'

Requesting to kindly provide me some script/solution to successfully copy and register the dll even when the UAC is elevated on a Windows 7 system

All NSIS installers should contain a RequestExecutionLevel attribute, it is inspected by Windows Vista and later when UAC is on.

Your installer needs to request administrator privileges when you are installing things in GAC, SxS etc:

Outfile RequireAdmin.exe
RequestExecutionLevel admin ;Require admin rights on NT6+ (When UAC is turned on)

!include LogicLib.nsh

Function .onInit
UserInfo::GetAccountType
pop $0
${If} $0 != "admin" ;Require admin rights on NT4+
    MessageBox mb_iconstop "Administrator rights required!"
    SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
    Quit
${EndIf}
FunctionEnd

Page InstFile

Section
SectionEnd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM