Executing CACLS With User Account After UAC Was Successful
Hi there,
I could really use some help here with my NSIS Installation. I've done all the preliminary searches and come up blank before posting this =).
Outline: This topic concerns the NSIS UAC Plugin, the NSIS Windows Version Detection code and the CACLS command. Operating Systems in question are Windows 2000 / XP Professional.
Summary: I have thousands of users who only have limited user accounts. They are in the medical industry, and this is HIPAA standard. I want them to be able to install my program, and I want my program to have access to where it lives in the Program Files directory. My installer uses the UAC Plugin to grant the user administrative rights. Then it installs the program. Then it checks the Windows version. For any Windows version BUT Vista, it executes the CACLS command to grant the Users group access to the Program Files folders (2) that my program must have access to.
Problem: When the installation is run from an administrative account, everything works fine. When the installation is run as a limited user account (even though the user gets administrative rights) the CACLS command does not give full control to "Users" to the specified folders.
Code Samples:
Function To Elevate User Privileges
Function UAC_Elevate
; Gets Administrative Permissions for install
; Aborts of Permissions cannot be obtained
LogText ""
LogText "_____________________________________________"
LogText ""
LogText "User Account Control -- Attempt to Run with Administrative credentials"
LogText "_____________________________________________"
LogText ""
LogText ""
UAC_Elevate:
UAC::RunElevated
StrCmp $0 1223 UAC_ElevationAborted ; UAC dialog aborted by user?
StrCmp $0 0 0 UAC_Err ; Error?
StrCmp $1 1 0 UAC_Success ;Are we the real deal or just the wrapper?
Quit
UAC_Err:
MessageBox mb_iconstop "You must have administrative credentials to install software, and this installer encountered an error when attempting to obtain these credentials$\n$\nError: $0$\n$\nPlease contact your systems administrator, or call NPF, Inc. at (760) 432-0145."
IfSilent +2 0
Abort
UAC_ElevationAborted:
MessageBox mb_iconstop "You must have administrative credentials to install software, and this installer was unable to obtain these credentials.$\n$\nError: Cancelled by user."
IfSilent +2 0
Abort
UAC_Success:
StrCmp $3 1 +5
StrCmp $1 3 0 UAC_ElevationAborted
MessageBox mb_iconstop "You must have administrative credentials to install software, and this installer was unable to obtain these credentials."
goto UAC_Elevate
FunctionEnd
Function to Get Windows Version
Function GetWindowsVersion
LogSet On
LogText ""
LogText ""
LogText "_____________________________________________"
LogText ""
LogText "Getting the Windows version"
LogText "_____________________________________________"
LogText ""
LogText ""
Push $R0
Push $R1
ClearErrors
ReadRegStr $R0 HKLM \
"SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
IfErrors 0 lbl_winnt
; we are not NT
ReadRegStr $R0 HKLM \
"SOFTWARE\Microsoft\Windows\CurrentVersion" VersionNumber
StrCpy $R1 $R0 1
StrCmp $R1 '4' 0 lbl_error
StrCpy $R1 $R0 3
StrCmp $R1 '4.0' lbl_win32_95
StrCmp $R1 '4.9' lbl_win32_ME lbl_win32_98
lbl_win32_95:
StrCpy $R0 '95'
Goto lbl_done
lbl_win32_98:
StrCpy $R0 '98'
Goto lbl_done
lbl_win32_ME:
StrCpy $R0 'ME'
Goto lbl_done
lbl_winnt:
StrCpy $R1 $R0 1
StrCmp $R1 '3' lbl_winnt_x
StrCmp $R1 '4' lbl_winnt_x
StrCpy $R1 $R0 3
StrCmp $R1 '5.0' lbl_winnt_2000
StrCmp $R1 '5.1' lbl_winnt_XP
StrCmp $R1 '5.2' lbl_winnt_2003
StrCmp $R1 '6.0' lbl_winnt_vista lbl_error
lbl_winnt_x:
StrCpy $R0 "NT $R0" 6
Goto lbl_done
lbl_winnt_2000:
Strcpy $R0 '2000'
Goto lbl_done
lbl_winnt_XP:
Strcpy $R0 'XP'
Goto lbl_done
lbl_winnt_2003:
Strcpy $R0 '2003'
Goto lbl_done
lbl_winnt_vista:
Strcpy $R0 'Vista'
Goto lbl_done
lbl_error:
Strcpy $R0 ''
lbl_done:
Pop $R1
Exch $R0
FunctionEnd
The CACLS Command
Call GetWindowsVersion
Pop $R0
StrCmp $R0 "Vista" 0 +2
execute "ICACLS $INSTDIR /GRANT *S-1-5-32-545:(F)"
StrCmp $R0 "Vista" +3 0
!execute 'CACLS "C:\Program Files\NPF DME" /E /P BUILTIN\Users:F'
!execute 'CACLS "C:\Program Files\NPF" /E /P BUILTIN\Users:F'
Any help would be greatly appreciated.