Re: User Access Rights
- From: DaveMo <david.mowers@xxxxxxxxx>
- Date: Thu, 21 Feb 2008 08:30:47 -0800 (PST)
On Feb 21, 8:21 am, Gary Larimer
<GaryLari...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
What is the correct method for using CreateFile() to open a file when the
user access rights may vary. Do you call function GetFileSecurity()
followed by an if() else construct which selects the proper form of
CreateFile():
iret = GetFileSecurity()
// code here determines if user has read only or read and write
// access and sets the variable access accordingly:
// access = 1 if read only right
// access = 2 if read and write access
// access = 3 for no access rights
if(access == 1) CreateFile(..., GENERIC_READ, ...);
else if(access == 2) CreateFile(...,GENERIC_READ l GENERIC_WRITE, ....);
else ... ; // error code
Or am i barking up the wrong tree? If so, is there a better or easier way
to do this? Thanks for any comments.
--
Gary Larimer
Normally you try to open a file with the minimum access level that is
required by the operation you are trying to perform. For example, if
your software needs to write something to a file it doesn't do much
good to open the file only for reading.
In summary, try to open the file with the access required by your
software and if the user doesn't have the right access levels then all
you can do is give him/her a good error message.
The only scenario I can think of that might take you down the path you
are going is if you have some software that will open a file but
leaves it to the system's access control to enforce whether the file
can be written to or not. I'm thinking Notepad.
In that case I would simply try opening first with R/W. If that fails,
try R. If that fails, report that the user has no access.
HTH,
Dave
.
- Follow-Ups:
- Re: User Access Rights
- From: Gary Larimer
- Re: User Access Rights
- Prev by Date: Effect of changing account password when already logged on
- Next by Date: Re: Domain authenticating non-domain accounts
- Previous by thread: Effect of changing account password when already logged on
- Next by thread: Re: User Access Rights
- Index(es):