Archive: SetFileOwner


SetFileOwner
Hi,
I'm running into an issue with AccessControl::SetFileOwner.

I've created a script that sets the ownership of a file to the current logged in user:


AccessControl::GetCurrentUserName "" "$0"
Pop $0
AccessControl::SetFileOwner "$INSTDIR\myfile.txt" $0


This works well in workgroups but does not work in a domain environment :weird:. In a domain, it actually assigns the local admin, instead of the logged in user. Im not sure if this is due to "RequestExecutionLevel admin".

Anyhow Id like it to assign the actual user that is logged on. I've tried to use UserMgr::GetCurrentDomain in conjuction with AccessControl::GetCurrentUserName but I believe my syntax was wrong.. (I'm new to NSIS so couldn't figure out the format :tinfoil:)

Any ideas? Any help is greatly appreciated !!! :) :D

If you are using RequestExecutionLevel admin then you can't really get the user.


I see. Is it possible to switch the RequestExecutionLevel back down then take ownership of the file? not sure if that would be appropriate in my scenario.:confused:

Any examples would really help. :p


As far as I know it's not possible to downgrade access level in Windows. But if it is possible, the only way to do it is to use shellexecuteas or runas.exe to start a new process. And for that you need to know the username, which you don't.

So, the best option is probably to use the UAC plugin to get two instances of your installer, one at userlevel and one at adminlevel. You can then get the username in the outer (userlevel) instance, and do all adminny stuff in the inner (admin) instance. Not recommended for beginners.


MSG thank you for suggestion.

I thought about something else. What if I run the dos command "takeown.exe" from the installer. Is that possible to do?