Solved

Checking directory permissions from within C++

Posted on 1998-01-07
5
933 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
  • 3
  • 2
5 Comments
 
LVL 32

Expert Comment

by:jhance
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now