Solved

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

Posted on 2011-09-26
6
577 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

739 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