Oct 10, 2008 #1 DRH192 Programmer Apr 25, 2005 96 GB Is there any way to retrieve the owner of a folder. I can easily get file details but the information you can retrieve for folders seems limited. Any help much appreciated Cheers
Is there any way to retrieve the owner of a folder. I can easily get file details but the information you can retrieve for folders seems limited. Any help much appreciated Cheers
Oct 14, 2008 #2 CautionMP Programmer Dec 11, 2001 1,516 US DRH192, This should get you moving in the right direction: http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct04/hey1007.mspx It's VBS so it should be pretty easy to port over to VBA Hope this helps [small]For the best results do what I'm thinking, not what I'm saying.[/small] (GMT-07:00) Mountain Time (US & Canada) Upvote 0 Downvote
DRH192, This should get you moving in the right direction: http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct04/hey1007.mspx It's VBS so it should be pretty easy to port over to VBA Hope this helps [small]For the best results do what I'm thinking, not what I'm saying.[/small] (GMT-07:00) Mountain Time (US & Canada)
Oct 17, 2008 #3 LauNai Programmer Oct 17, 2008 2 CH Yes it is working find here for VBA Public Function fctGetOwner(strFile As String) As String Dim objWMIService As Object Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") Set colitems = objWMIService.ExecQuery _ ("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting='" & strFile & "'}" _ & " WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner") For Each objitem In colitems ' MsgBox objItem.ReferencedDomainName ' MsgBox objItem.AccountName fctGetOwner = objitem.AccountName Next End Function Upvote 0 Downvote
Yes it is working find here for VBA Public Function fctGetOwner(strFile As String) As String Dim objWMIService As Object Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") Set colitems = objWMIService.ExecQuery _ ("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting='" & strFile & "'}" _ & " WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner") For Each objitem In colitems ' MsgBox objItem.ReferencedDomainName ' MsgBox objItem.AccountName fctGetOwner = objitem.AccountName Next End Function