Solved

Checking directory permissions from within C++

Posted on 1998-01-07
5
946 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Modify static variables within a class in VC++ 3 95
SendMessage fails while PostMessage works 2 107
PDF library for Delphi 2 104
convert char array to number in c 5 83
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

910 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

19 Experts available now in Live!

Get 1:1 Help Now