Re: User Access Rights



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

.



Relevant Pages

  • Closing opened file handles
    ... I have a .NET CF app that calls some functions in a third party DLL ... One of the function calls opens a data file and ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Problem with Get
    ... but when the app starts I do ... check for the existence of the data file and to calculate the number of ... Is there some advantage to specifying the type of random access in the ... Open statement instead of just For Random As? ...
    (microsoft.public.vb.general.discussion)
  • Re: older delphi
    ... >The data file is a flat text file. ... >app to tray and restore it, or when I exit the app using the close box ... >in the upper right with a confirm exit dialog. ... The tray icon also disappears ...
    (alt.comp.lang.borland-delphi)
  • Re: File Activity
    ... that updates a 60mg Data File. ... This flag is ... We had a similar situation and managed it by having the first app close the ... data file, then write out a small "done" file. ...
    (microsoft.public.vb.general.discussion)
  • Re: Unparsable Record
    ... Make a copy of your data file. ... If that fails, delete 11 more columns so only the first 11 ... I'm getting the famous unparsable record error when importing ...
    (microsoft.public.access.externaldata)