Re: User Access Rights
- From: Gary Larimer <GaryLarimer@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 21 Feb 2008 11:30:00 -0800
Thanks for thr information. When the app is run by the data file owner, I
would like read and write capabilities, but when the app is run under a
Limited User Account (XP Home) I would like the Limited User to be able to
read the data file even if he did not create it. (I am assuming that the
Limited User has read access rights for the data file.) So, the following
code would be an appropriate way to achieve that:
// try GENERIC_READ l GENERIC first
iret = CreateFile(..., GENERIC_READ l GENERIC_WRITE, ....);
if(iret == INVALID_HANDLE_VALUE) {
// if 1st attemp fails try just GENERIC_READ
iret = CreateFile(..., GENERIC_READ, ....) ;
if(iret == INVALID_HANDLE_VALUE) {
iret = MessageBox(..., 'Access Denied', ...);
}
}
--
Gary Larimer
"DaveMo" wrote:
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
- References:
- Re: User Access Rights
- From: DaveMo
- Re: User Access Rights
- Prev by Date: Verify timestamp with CryptoApi
- Next by Date: Re: Domain authenticating non-domain accounts
- Previous by thread: Re: User Access Rights
- Next by thread: Re: User Access Rights
- Index(es):
Relevant Pages
|