Solved

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

Posted on 2011-09-26
6
540 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 41

Accepted Solution

by:
dlmille earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks very much Dave!!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
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…
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…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now