Jump to content

Getting File And Directory Owners

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Sharper_Software

Sharper_Software

    Newbie

  • Members
  • PipPip
  • 17 posts
I have noticed not a lot of people know how to get the basic IO.file Owner information of a file/dir so i will show an example that you can play around with. :thumbup1:


'Required for The Directory Query.
'Required for The NT User Account Query.


Imports System.IO

Imports System.Security

Imports System.Security.Principal


Just Add this to a form, and add a reference to it in the form load events or a button event.

Public sub getowner()

          Try

                Dim Target_Dir as string

                Dim di As New DirectoryInfo(Target_Dir)

                Dim ds As AccessControl.DirectorySecurity = di.GetAccessControl()

                Dim owner As NTAccount = CType(ds.GetOwner(GetType(NTAccount)), NTAccount)

                msgbox("File Owner: " & owner.ToString)

            Catch ex As Exception

                msgbox("File Owner Error: " & ex.Message)

            End Try

end sub

Hope this helps anyone who is looking.

Cheers

-Sharper Software
The Future Of Network Defense Systems, Today.

#2
Jarryd

Jarryd

    Learning Programmer

  • Members
  • PipPipPip
  • 63 posts
Nice work on this man,