How to get file owner information

C

Carlos

I use the below codes downloaded from
http://www.visualbasicforum.com/showthread.php?t=158264 to perform a
recursive search of files and folders. I can obtain most of the information
such as the filename, last modified, last accessed, last created but I'm not
able to get the "owner" information which is the most important info that I
need to get.

I want to know who "creates" this file. By the way I use VB.NET languages
with VS.NET IDE.

Can someone enlighthen me or direct me to some sample page on how the codes
to get file information (security?)

Thanks

Carlos.

----------------------------------------------------------------

Private Overloads Function Recursive(ByVal strPath As String)

Dim oDir As New System.IO.DirectoryInfo(strPath)
Dim oSubDir() As System.IO.DirectoryInfo
Dim oFiles() As System.IO.FileInfo
Dim i As Int32

oFiles = oDir.GetFiles
For i = 0 To oFiles.Length - 1
Debug.WriteLine(oFiles(i).Name.ToString)
Next


oSubDir = oDir.GetDirectories()
For i = 0 To oSubDir.Length - 1
Debug.WriteLine(oSubDir(i).Name.ToString)
'more code to do whatever here

Call Recursive(oSubDir(i), 1)
Next

End Function

Private Overloads Function Recursive(ByVal oDir As System.IO.DirectoryInfo,
ByVal intLevel As Int32)

Dim oSubDir() As System.IO.DirectoryInfo
Dim oFiles() As System.IO.FileInfo
Dim i As Int32

oFiles = oDir.GetFiles
For i = 0 To oFiles.Length - 1
Debug.WriteLine(New String(" ", intLevel) & ">" &
oFiles(i).Name.ToString)
Next

oSubDir = oDir.GetDirectories()
For i = 0 To oSubDir.Length - 1
Debug.WriteLine(New String(" ", intLevel) &
oSubDir(i).Name.ToString)
'more code to do whatever here

Call Recursive(oSubDir(i), intLevel + 1)
Next

End Function
 
B

Björn Holmgren

Carlos said:
I use the below codes downloaded from
http://www.visualbasicforum.com/showthread.php?t=158264 to perform a
recursive search of files and folders. I can obtain most of the information
such as the filename, last modified, last accessed, last created but I'm not
able to get the "owner" information which is the most important info that I
need to get.

I want to know who "creates" this file. By the way I use VB.NET languages
with VS.NET IDE.

Can someone enlighthen me or direct me to some sample page on how the codes
to get file information (security?)


Call GetNamedSecurityInfo asking for OWNER_SECURITY_INFORMATION and you'll
get the owner's SID. Then call LookupAccountSID to get the account name.

Or use WMI. The GetSecurityDescriptor method of the
LogicalFileSecuritySetting class retrieves a SecurityDescriptor object. One
of the properties of that object is the owner (name, domain etc).

WMI should be the most straightforward method since it's part of the
framework (if I recall correctly).

Unfortinately, since you're using VB.NET I'm unable to provide any example
code. This group is for "classic" VB only (version 6 and below).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top