Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Checking directory permissions from within C++

Posted on 1998-01-07
5
Medium Priority
?
979 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 100 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

636 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