Hi:
Is it possible to use madSecurity to determine if the current user can create or write to a specific file.
For example, if the app needs to update a file at:
\\server\someshare\somefile.txt
Can I determine access before trying to update the file?
Thanks,
Mark
Determining if I can access certain file
-
- Posts: 2
- Joined: Mon Nov 07, 2005 7:42 pm
Well, theoretically it's possible. I mean you can list all the elements of the ACL. However, you'd need quite a complicated logic to try and find out what the ACL sais about your user. So I don't recommend this approach. The most simple way is to try to open the file. If it succeeds then you had enough rights.
-
- Posts: 2
- Joined: Mon Nov 07, 2005 7:42 pm
Thanks for the reply. I came to the same conclusion shortly after I posted this message. I am now using successfully using:
function IsFileAccessible(fName: string): boolean;
var
HFileRes: HFILE;
begin
Result := false;
HFileRes := CreateFile(
pchar(fName),
GENERIC_READ or GENERIC_WRITE,
0,
nil,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
0);
Result := (HFileRes <> INVALID_HANDLE_VALUE);
if Result then CloseHandle(HFileRes);
end;
function IsFileAccessible(fName: string): boolean;
var
HFileRes: HFILE;
begin
Result := false;
HFileRes := CreateFile(
pchar(fName),
GENERIC_READ or GENERIC_WRITE,
0,
nil,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
0);
Result := (HFileRes <> INVALID_HANDLE_VALUE);
if Result then CloseHandle(HFileRes);
end;