Link to home
Start Free TrialLog in
Avatar of gllanderas
gllanderasFlag for Spain

asked on

Howto get the file permissions in a Windows 2000/XP

I want to get the permissions defined for the files stored in a Windows 2000 or in a Windows XP within a Visual Basic 6.0 program.

How can I get them?

Thanks. :)
Avatar of sajuks
sajuks

Avatar of gllanderas

ASKER

Thanks, sajuks, but when I run this code:

https://www.experts-exchange.com/questions/10194747/Permissions-of-Files.html

I see this at the debug window:

0 - 0 -  - Change
0 - 0 -  - Read
0 - 0 -  - Read

If I run this:

   ACEs = GetAccessControlElements("C:\test.txt", SE_FILE_OBJECT)
   With ACEs
      For I = 0 To UBound(.List)
         With .List(I)
            Debug.Print .TRUSTEE.TrusteeForm & " - " & .TRUSTEE.TrusteeType & " - " & .TRUSTEE.ptstrName & " - " & AccessRights(.grfAccessMode, .grfAccessPermissions)
            Debug.Print "   " & Len(.TRUSTEE.ptstrName) & " - " & Asc(Mid(.TRUSTEE.ptstrName, 1, 1)) & " - " & Asc(Mid(.TRUSTEE.ptstrName, 2, 1)); ""
         End With
      Next
   End With

I obtain this:

0 - 0 -  - Change
   2 - 1 - 5
0 - 0 -  - Read
   2 - 1 - 5
0 - 0 -  - Read
   2 - 1 - 2


Any ideas? I need to obtain the name of the user who has permissions defined in the file.
i thought u just wanted to know what permission had been set on the file....sorry
Try to read these mskb:
(How To Use (High/ Low)-Level Access Control APIs from Visual Basic)
http://support.microsoft.com/kb/295004/EN-US/
http://support.microsoft.com/default.aspx?scid=kb;en-us;316440
lv, the low-level access control APIs should be used only on Windows NT 4.0-and-earlier operating systems. See the note of the article of Microsoft.
http://support.microsoft.com/default.aspx?scid=kb;en-us;316440


And with the other article, http://support.microsoft.com/kb/295004/EN-US/
I can change the permissions, but the problem is when I try to get present permissions of the file.

I think the problem is at GetExplicitEntriesFromAcl API function. :-(

Thanks, anyway.
Yes, sajuks, I want to know what permissions had been set... and the login (or SID) of the user. Something like:

everyone: read
administrator: write
MiPC\Guiller: write

Well...from those resources you should have reached:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthz/security/buildexplicitaccesswithname.asp

"Unwinding" structure by structure, calling function by function you could get the desired result.
But there is another (more effortless) possibility - use microsoft cacls.exe or xcacls.exe utility.
Well, I will try xcalcs.exe, then.

The question is that this will be a server process called by various clients simultaneously, so I prefer to use API calls instead of calling a command line program (and capturing the output).

I will wait a few days until try xcalcs.exe. Perhaps somebody knows why fails the code at

https://www.experts-exchange.com/questions/10194747/Permissions-of-Files.html
I have found another way to get the file permissions: ussing winmgmts.

http://www.microsoft.com/technet/scriptcenter/scripts/security/dacls/sedcvb01.mspx

This works fine. :)
ASKER CERTIFIED SOLUTION
Avatar of PAQ_Man
PAQ_Man
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial