View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
PJ PJ is offline
external usenet poster
 
Posts: 112
Default File owner attributes through Excel VBA

Joel,

That works like a charm. For my needs, I'm actually looking for a specific
file so I hard coded the name and set it to prompt the user running the macro
with the name of the person associated with creating the file. The file is a
temp file created by a 3rd party program so they need to track the person
down and have them exit the application before they can run the Excel macro
in it's entirety.

Thanks for the help!
PJ


"Joel" wrote:

I found an easier way of getting the file owner without having to use a DLL.
Try this code

Sub owner()
Dim Folder As String
Dim FName As String

Folder = "c:\temp\"
RowCount = 1
FName = Dir(Folder & "*.*")

Do While FName < ""
Range("A" & RowCount) = Folder & FName
Range("B" & RowCount) = GetFileOwner(Folder, FName)

RowCount = RowCount + 1
FName = Dir()
Loop



End Sub

Function GetFileOwner(fileDir As String, fileName As String) As String

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



"PJ" wrote:

Hi Joel,

I work in an all Windows environment and have read/write access to the
folder where the particular files are stored. I usually right-click on the
file from Windows Explorer, choose Properties, click the Advanced button on
the Security tab, and finally switch to the Owner tab which shows me the
current owner. If there is any way to return the owner's name using VBA that
would be great.

PJ

"Joel" wrote:

If you can get the ownership through any tool then you should be able to get
the ownship through VBA since VBA can call any application. The only way I
know of to get a file permission on a server is to be able to map a drive to
the server or login into the server. If you don't have permission to do
either of these operations then you won't be able to get the ownship through
VBA.

I you tell me how you get the ownship of the file without using VBA then I
can write code in VBA to do the same operation. VBA can call any DLL and
network login and transversing the file system to get the owner is possible
through a Win32 Dll.

"PJ" wrote:

Is it possible to use VBA to determine the owner of a file saved on a network
share? I am trying to get the ID of the person logged in when the file was
created on the server. The file itself is not an MS office file however, I'm
just trying to get the name of the owner as part of my macro in Excel.