Solved

Excel VBA - How to find out how create the windows folder or directory.

Posted on 2011-09-26
6
563 Views
Last Modified: 2012-05-12
Hi Experts,

Can you please help guilde me in the right direction with vba coding to extract the "Author" property from a Windows directory. I need to know who created the folder that sits on a local drive.

I'm currently doing this manually as can be seen in attached image.
Thanks in advance.
Ric Folder's Author
0
Comment
Question by:RiCzN
  • 4
  • 2
6 Comments
 
LVL 42

Expert Comment

by:dlmille
ID: 36648402
Here's an excellent tip to access file properties, including author:

http://www.codeguru.com/forum/showthread.php?t=372929


Dave
0
 
LVL 42

Expert Comment

by:dlmille
ID: 36652789
You need to add a reference to the Microsoft Shell Controls and Automation library to use the shell objects in the getFileAttributes() function...

This gives you file properties, of course.  I'm checking to see if folder properties are also available...

0
 
LVL 42

Expert Comment

by:dlmille
ID: 36663932
I'm finding all kinds of sources listing folder properties.  None of them mention author.  I don't think I have ever seen it.  Sorry for the question, but can you show an image of an author associated with a folder?  I tried what you did on my machine and get null results.

Thanks for the clarification.

Cheers,

Dave
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 42

Accepted Solution

by:
dlmille earned 500 total points
ID: 36704140
Ok.  I think I've got it.  I'm not sure what your picture is showing will give you the author of the folder.  However, if you right click the folder, then left-click on properties, navigate to the security tab and click "Advanced", then go to the OWNER tab, you'll see who the current owner is.  Unless ownership was transferred after creation, it should give you either the user or the user's group (e.g., if the user was an Administrator, it might list Administrators as the owner) as the author/owner.

Please take a look at this:

The function makes use of the ADsSecurityUtility object, which is in the Active DS Type Library.  The code uses late binding, but you can investigate the object via google - plenty of sources once you know what to search for, and also via VBA Watch window.

Here's the code:
 
Option Explicit
Sub getFolderAuthor()
Dim fPath As String

    fPath = GetFolderName("Select Folder for Author/Owner identification")
    If fPath <> "" Then
        MsgBox "The Author/Owner of Folder: " & fPath & " is: " & GetFolderFileOwner(fPath)
    End If
    
End Sub
Function GetFolderFileOwner(fileDir As String, Optional fileName As String) As String

    'On Error Resume Next
    Dim secUtil As ADsSecurityUtility
    Dim secDesc As Object
    Set secUtil = CreateObject("ADsSecurityUtility")
    Set secDesc = secUtil.GetSecurityDescriptor(fileDir & fileName, 1, 1)
    
    GetFolderFileOwner = secDesc.Owner
End Function

Open in new window


I included a test subroutine, which is called when you click the button on the attached workbook - select a folder and it will provide the owner/author back as a result of the getSecurityDescriptor interrogation.

Let me know this works for you.  On my machine, I'm an admin, so all my files are owned by the group "Administrators".  I'd like to know if you get user names or only the group where they reside...

Cheers,

Dave
getFolderFileOwnerAuthor-r1.xlsm
0
 

Author Comment

by:RiCzN
ID: 36708735
Hi Dave, thanks for the quick reply. I wasnt expecting anyone to get back to me so quickly. Ill give your suggestions a go when im in the office tomorrow. Thanks once again.
0
 

Author Closing Comment

by:RiCzN
ID: 36907989
Thanks very much Dave!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question