Solved

Checking directory permissions from within C++

Posted on 1998-01-07
5
967 Views
Last Modified: 2011-09-20
My program saves files to a directory selected by the user.  Since the user could be an administrator with full read/write permissions, or a guest with limited access to only a few directories, how can I have the program check for write access on a specific directory without actually creating a "test" file in that directory?
0
Comment
Question by:DenMan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 1177728
This is an OS dependent problem.  Normally you just try the operation and if it fails, the error code will tell you that you didn't have permission to write the data.
0
 

Author Comment

by:DenMan
ID: 1177729
The particular case I have in mind is saving files to a directory with Add+Read permissions.  A file can be created, but not removed.  How can I verify that this directory can be written to without creating an unremovable temp file?
0
 
LVL 32

Expert Comment

by:jhance
ID: 1177730
Like I said, it's OS dependent (i.e. it's not a part of the C/C++ standard libraries).  If you could provide some information about your run-time environment, I might be able to help.
0
 

Author Comment

by:DenMan
ID: 1177731
Sure...I'm running NT 4.0, with it's security features (read, add, change) in use on certain directories.  In this particular case, I have a directory that is Read+Add (i.e. no changing or deleting), so if I create a test file to check for write-access, I can't delete it after it's created.

Does that help?
0
 
LVL 32

Accepted Solution

by:
jhance earned 50 total points
ID: 1177732
Yes, that does help.  Under Windows NT you can use the Win32 API GetFileSecurity() call to get the permissions associated with any file system object.  Of course, this ONLY applies to NTFS volumes as FAT volumes have no security.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question