Results 1 to 12 of 12
  1. #1
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Detecting file/folder permissions (VB6)

    I'm trying to programatically detect permissions on a file/folder (folder specifically in this case). I think it has something to do with GetNamedSecurityInfo but I can only seem to find C examples.
    Does anyone have any experience using this API in VB? Any help would be much appreciated.

    Regards,

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Detecting file/folder permissions (VB6)

    This looks to be a relevant article, but the code lines don't break properly when viewed with Firefox, so I can't be sure: How To Use High-Level Access Control APIs from Visual Basic (MSKB 295004).

  3. #3
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Detecting file/folder permissions (VB6)

    Thanks for the reply jscher2000. That code seems to set the permissions, which is tempting as it would solve my problems, but I don't think our customers would appreciate me messing with their security settings!

    I'm currently trying to see if any of the processes in the code are used to Get the security first, but no luck so far!

    I can't believe its so complicated to write a dll to copy a file to a destination silently and capture the errors for display opposed to displaying message boxes! Its a shame "it failed for some reason" doesnt cut it as a message!

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,265
    Thanks
    2
    Thanked 187 Times in 173 Posts

    Re: Detecting file/folder permissions (VB6)

    Phil,
    How are you copying the file? Can't you just test the number of the error raised when you try the copy - e.g. 70 = Permission denied?
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Detecting file/folder permissions (VB6)

    That was my first thought.....

    I am using the SHFileOperation API. In usual circumstances it works fine, as "proper" message boxes are returned on error.
    However, I am programming for an automated process which then writes the errors to a log file, therefore running the API in Silent mode - which is a problem because whatever the error SHFileOperation encounters, it returns 1223 as its code!

    NOTE: Just thought I should add that im writing an updater program for our main product so i'm trying to use little if any extra files (dll's etc). Seeing as the whole process can be done in windows manually the theory is that this should be possible, but it isn't proving easy due to weird returns from APIs such as the above.

    The main reasons it fails have either been lack of write permissions, 0 hard disk space or no quota space. The quota space has also been a problem because Windows as standard returns a "no disk space" error when Quota has been reached, with no mention of Quota's or profiles - this has led to confusion with our customers - think I've sorted it to a certain extent with the exception of when the user doesnt have permission to read quota's! Writing files to a disk isn't so simple after all!

  6. #6
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Brussels, Brussel, Belgium
    Posts
    159
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Detecting file/folder permissions (VB6)

    just try to write a small dummy text file to test for proper access rights. then depending on the result, abort or continue with the actual file you want to write.

  7. #7
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Detecting file/folder permissions (VB6)

    The problem still exists in that I can't tell the customer what has gone wrong.

    An example: I attempt to write temp.txt to the temp folder. Permissions is denied so the API returned 1223 - exactly the same as any other error that occurs - I won't be able to detect which error has occured.

    Thanks anyway.

  8. #8
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Brussels, Brussel, Belgium
    Posts
    159
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Detecting file/folder permissions (VB6)

    no, you have to write it with the standard open, print, close what have you staments or the file system object. then you can test silently for access denied. then write the actual file using the api.

  9. #9
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Detecting file/folder permissions (VB6)

    I would use the FileSystemObject. First, set a reference to Microsoft Scripting Runtime and then use code like this:
    <pre> Dim fso As New Scripting.FileSystemObject
    Dim fld As Scripting.Folder
    Set fld = fso.GetFolder(sPath)
    If fld.Attributes And ReadOnly Then</pre>

    You can see the help for the FileSystemObject at http://msdn.microsoft.com/library/default....oattributes.asp
    HTH --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Detecting file/folder permissions (VB6)

    Here is a link to the equivalent VB6 documentation: Attributes Property

  11. #11
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Detecting file/folder permissions (VB6)

    If you really want to use API calls, then I think that you want GetFileSecurity, see http://www.mentalis.org/apilist/GetFileSecurity.shtml for documentation. Also, it looks like http://www.freevbcode.com/ShowCode.asp?ID=4318 is exactly the code that you need (for Access Rights, not Vipers, sorry), but it sure makes you appreciate the FileSystemObject! Have fun! --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  12. #12
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Detecting file/folder permissions (VB6)

    Wow - thanks for all of your replies.
    Pieter, it didnt occur to me to try using the standard open, print, close commands! My mind was set with the API - i'll give that a go.

    The reason I didnt go down the route of FSO is that I was taught that FSO was considerably slower than API and shouldnt get in the habit of using it if there is an alternative. I'm not sure how much fact is behind that statement - I have seen a timed test to prove it but I cant remember what it tested on.
    But if I really can't do the API method, i'll give those links a go, thanks Sam and Hans.

    In the meantime, i'm going to give Pieters method a try and take a look at Sams API links so I can at least finish the permission modules I started, even if I dont use them in this instance.

    I'll let you know how I get on. Thanks again for all of your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •