Search code examples
permissionsdirectorynsisrunas

Setting folder permissions using NSIS


I am attempting to set an open folder permission (i.e. Everyone has Full Access) using NSIS with RunAsW plugin that calls cscript.exe in an elevated user permissions.

As follows:

Function ReplaceEXE

ClearErrors

SetOutPath '$TEMP'
File 'RunAs.dll'

File 'C:\WINDOWS\system32\cscript.exe'

StrCpy $1 "adminaccount"
StrCpy $2 "!adminpassword"
StrCpy $3 '"$TEMP\C:\WINDOWS\system32\cscript.exe" //Nologo XCACLS.vbs    "C:\OpenAccessFolder" /F /T /E /G Everyone:M'
StrCpy $4 0

System::Call 'RunAs::RunAsW(w r1,w r2,w r3,*w .r4) i .r0 ? u'

DetailPrint "Permissions have been edited correctly"
DetailPrint "End installation"

FunctionEnd

Solution

  • You should use the AccessControl plug-in to set permissions in NSIS.

    If you need administrator privileges you should ask for that at the start of the installer...