views:

691

answers:

3

Greetings!

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

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

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

Thanks

Evan

+1  A: 

Use sec api. You can ask on Adv. Win32 api newsgroup : news://194.177.96.26/comp.os.ms-windows.programmer.win32 where it has often been discussed (C/C++ code)

+2  A: 

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

It's not a C++ library but it still counts as elegant because it directly does what you want...

Frederik Slijkerman
+1  A: 

There are many Windows security functions, although I wouldn't call their usage 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. :)

Nick