3

I've been searching over the internet how to retrieve permissions and ownership of a file using win32 api, and yet I have no answer.

I'm new with the win32 api , read some guides from the internet, tried to analyze some code associating with this api and still I'm clueless.

Could you guys help me out with some piece of advice or some directions , tips etc.

I'm sorry that I can't be more specific than that by adding some code, I don't see any reason to import any code of my own since the only remaining function is the one retrieving this information and the rest is simple(User interface and etc).

avi sabag
  • 39
  • 1
  • 1
  • 2
  • While not part of the WIN32 API, the CRT contains functions like [`_fstat`](http://msdn.microsoft.com/en-us/library/221w8e43.aspx) that can be used to get read/write permissions. – Some programmer dude Aug 01 '12 at 08:37
  • The link in @Someprogrammerdude's comment above currently redirects to https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/fstat-fstat32-fstat64-fstati64-fstat32i64-fstat64i32?redirectedfrom=MSDN&view=msvc-170 – AJM Mar 20 '23 at 15:06

2 Answers2

3

See Retrieving NTFS Permissions with C++. But, basically, you call GetFileSecurity to get a security descriptor for the file. From that, you can get the access control list (ACL) and the owner and permissions.

AJM
  • 1,317
  • 2
  • 15
  • 30
Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
  • Linked URLs currently redirect to https://www.devx.com/c-zone/16711/ and https://learn.microsoft.com/en-gb/windows/win32/api/winbase/nf-winbase-getfilesecuritya?redirectedfrom=MSDN – AJM Mar 20 '23 at 15:05
1

See this example which finds the owner of a file using GetSecurityInfo and LookupAccountSid functions.

AJM
  • 1,317
  • 2
  • 15
  • 30
Andriy
  • 8,486
  • 3
  • 27
  • 51
  • Linked URL currently redirects to https://learn.microsoft.com/en-gb/windows/win32/secauthz/finding-the-owner-of-a-file-object-in-c--?redirectedfrom=MSDN – AJM Mar 20 '23 at 15:04