3

I am trying to change a file's ownership through c++ in windows(windows 7 and up) to a specific user. I have read through this example but it does not seem to be of much help. I would like to be able to create a function like SetFileOwner(LPTSTR user, LPTSTR fileStr) that sets the owner of fileStr to be the specified user.

It seems that I need a SID to set the owner and then use SetNamedSecurityInfo. Is there another option that will allow me to set ownership by username? Is there a way to get SID from username(sorry if this question is stupid - I am not really into how windows rights and ownership work)?

Ivaylo Strandjev
  • 66,530
  • 15
  • 117
  • 170

1 Answers1

3

To translate username to SID, use LookupAccountName.

tylerl
  • 29,320
  • 12
  • 78
  • 110
  • Thank you for your answer! This seems to be just what I was looking for. I will try to prototype later and will accept your answer if this works – Ivaylo Strandjev Sep 14 '12 at 06:59