Code for checking write permissions for directories in Win2K / XP

Hello!

I am trying to check directory write permissions from a Windows MFC / ATL program using C ++. My first guess is to use the C-standard _access function, for example:

if (_access("C:\mydir", 2) == -1) // Directory is not writable. 

But apparently in Windows 2000 and XP, _access cannot determine directory permissions. (i.e. the Security tab in the Properties dialog box when you right-click on a directory in Explorer). So, is there an elegant way to determine write permissions in Windows 2000 / XP using any of the Windows C ++ libraries? If so, how?

thanks

Evan

+4
source share
3 answers

You can call CreateFile with GENERIC_WRITE access to verify this. http://msdn.microsoft.com/en-us/library/aa363858(VS.85).aspx

It is not a C ++ library, but it is still considered elegant because it directly does what you want ...

+4
source

Use sec api. You can ask about Adv. Win32 Newsgroup api: News: //194.177.96.26/comp.os.ms-windows.programmer.win32 where it was often discussed (C / C ++ code)

+1
source

There are many Windows security features , although I would not call their use particularly elegant. I would recommend GetNamedSecurityInfo as a general solution, but the CreateFile solution has a certain simplicity and directness, which I can also appreciate. :)

+1
source

Source: https://habr.com/ru/post/1277703/


All Articles