Solved

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

Posted on 2011-09-26
6
559 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 41

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 41

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 41

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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 41

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

809 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