Find the Owner of a folder

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SimeonD

    Find the Owner of a folder

    Hi
    Is there a way I can fnd the Owner of a folder, using vb.net? I know how to
    find the permissions, but I can't figure how to find the owner.
    Thanks
    SimeonD


  • Armin Zingler

    #2
    Re: Find the Owner of a folder

    "SimeonD" <simeond@nospam .nospamschrieb
    Hi
    Is there a way I can fnd the Owner of a folder, using vb.net? I know
    how to find the permissions, but I can't figure how to find the
    owner.
    Thanks
    SimeonD
    1. Create a DirectoryInfo object
    2. Call it's GetAccessContro l method. It returns a DirectorySecuri ty
    object.
    3. Call the GetOwner method of the returned object. Something like this:

    Dim sidType As Type =
    GetType(System. Security.Princi pal.SecurityIde ntifier)
    Dim owner As System.Security .Principal.Secu rityIdentifier

    owner = DirectCast(DS.G etOwner(sidType ),
    Security.Princi pal.SecurityIde ntifier)

    (DS is the DirectorySecuri ty object)

    4. Owner is the owner. :)


    AZ

    Comment

    • Linda Liu[MSFT]

      #3
      RE: Find the Owner of a folder

      Thanks AZ for your reply!

      Hi Simeon,

      As AZ has suggested, we can get the DirectorySecuri ty object by calling
      DirectoryInfo.G etAccessControl method first and then get the owner by
      calling the DirectorySecuri ty.GetOwner method passing NTAccount as the
      parameter.

      The following is a sample:

      Imports System.IO
      Imports System.Security .AccessControl
      Imports System.Security .Principal

      Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
      System.EventArg s) Handles MyBase.Load
      Dim di As New DirectoryInfo(" directoryname")
      Dim ds As DirectorySecuri ty = di.GetAccessCon trol()
      Dim owner As NTAccount = CType(ds.GetOwn er(GetType(NTAc count)),
      NTAccount)
      End Sub

      Hope this helps.
      If you have any question, please feel free to let me know.

      Sincerely,
      Linda Liu
      Microsoft Online Community Support

      Delighting our customers is our #1 priority. We welcome your comments and
      suggestions about how we can improve the support we provide to you. Please
      feel free to let my manager know what you think of the level of service
      provided. You can send feedback directly to my manager at:
      msdnmg@microsof t.com.

      =============== =============== =============== =====
      Get notification to my posts through email? Please refer to
      Gain technical skills through documentation and training, earn certifications and connect with the community

      ications.

      Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
      where an initial response from the community or a Microsoft Support
      Engineer within 1 business day is acceptable. Please note that each follow
      up response may take approximately 2 business days as the support
      professional working with you may need further investigation to reach the
      most efficient resolution. The offering is not appropriate for situations
      that require urgent, real-time or phone-based interactions or complex
      project analysis and dump analysis issues. Issues of this nature are best
      handled working with a dedicated Microsoft Support Engineer by contacting
      Microsoft Customer Support Services (CSS) at
      http://msdn.microsoft.com/subscripti...t/default.aspx.
      =============== =============== =============== =====
      This posting is provided "AS IS" with no warranties, and confers no rights.


      Comment

      • kimiraikkonen

        #4
        Re: Find the Owner of a folder

        On May 12, 8:04 am, v-l...@online.mic rosoft.com (Linda Liu[MSFT])
        wrote:
        Thanks AZ for your reply!
        >
        Hi Simeon,
        >
        As AZ has suggested, we can get the DirectorySecuri ty object by calling
        DirectoryInfo.G etAccessControl method first and then get the owner by
        calling the DirectorySecuri ty.GetOwner method passing NTAccount as the
        parameter.
        >
        The following is a sample:
        >
        Imports System.IO
        Imports System.Security .AccessControl
        Imports System.Security .Principal
        >
        Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
        System.EventArg s) Handles MyBase.Load
        Dim di As New DirectoryInfo(" directoryname")
        Dim ds As DirectorySecuri ty = di.GetAccessCon trol()
        Dim owner As NTAccount = CType(ds.GetOwn er(GetType(NTAc count)),
        NTAccount)
        End Sub
        >
        Hope this helps.
        If you have any question, please feel free to let me know.
        >
        Sincerely,
        Linda Liu
        Microsoft Online Community Support
        >
        Delighting our customers is our #1 priority. We welcome your comments and
        suggestions about how we can improve the support we provide to you. Please
        feel free to let my manager know what you think of the level of service
        provided. You can send feedback directly to my manager at:
        msd...@microsof t.com.
        >
        =============== =============== =============== =====
        Get notification to my posts through email? Please refer tohttp://msdn.microsoft. com/subscriptions/managednewsgrou ps/default.asp...
        ications.
        >
        Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
        where an initial response from the community or a Microsoft Support
        Engineer within 1 business day is acceptable. Please note that each follow
        up response may take approximately 2 business days as the support
        professional working with you may need further investigation to reach the
        most efficient resolution. The offering is not appropriate for situations
        that require urgent, real-time or phone-based interactions or complex
        project analysis and dump analysis issues. Issues of this nature are best
        handled working with a dedicated Microsoft Support Engineer by contacting
        Microsoft Customer Support Services (CSS) athttp://msdn.microsoft. com/subscriptions/support/default.aspx.
        =============== =============== =============== =====
        This posting is provided "AS IS" with no warranties, and confers no rights..
        Hi,
        To make syntax shorter, "my" namespace can also be used:
        Dim owner As NTAccount = _ My.Computer.Fil eSystem.GetDire ctoryInfo("c:
        \resized").GetA ccessControl.Ge tOwner(GetType( NTAccount))

        Thanks,

        Onur Güzel

        Comment

        • Armin Zingler

          #5
          Re: Find the Owner of a folder

          "kimiraikko nen" <kimiraikkonen8 5@gmail.comschr ieb
          Hi,
          To make syntax shorter, "my" namespace can also be used:
          Dim owner As NTAccount = _ My.Computer.Fil eSystem.GetDire ctoryInfo("c:
          \resized").GetA ccessControl.Ge tOwner(GetType( NTAccount))

          ==========

          I think Linda Liu's example is exactly the same, but just split into
          some lines to make the steps easier to understand.

          The My namespaces is not required at all. At least in this case it's not
          the direct way. The call is delegated to
          Microsoft.Visua lBasic.FileIO.F ileSystem.GetDi rectoryInfo which again
          creates a Sytem.IO.Direct oryInfo object. So, I'd directly do the latter
          and get rid of the superfluous My-garbage.


          Armin

          Comment

          • Linda Liu[MSFT]

            #6
            RE: Find the Owner of a folder

            Hi Simeon,

            I am reviewing this post in the newsgroup and would like to know the status
            of this issue.

            If you have any question, please feel free to let me know.

            Thank you for using our MSDN Managed Newsgroup Support Service!

            Sincerely,
            Linda Liu
            Microsoft Online Community Support

            Delighting our customers is our #1 priority. We welcome your comments and
            suggestions about how we can improve the support we provide to you. Please
            feel free to let my manager know what you think of the level of service
            provided. You can send feedback directly to my manager at:
            msdnmg@microsof t.com.

            This posting is provided "AS IS" with no warranties, and confers no rights.


            Comment

            • SimeonD

              #7
              Re: Find the Owner of a folder

              Issue resolved, thanks to AZ and Linda.



              "Linda Liu[MSFT]" <v-lliu@online.mic rosoft.comwrote in message
              news:wNaewVbtIH A.1788@TK2MSFTN GHUB02.phx.gbl. ..
              Hi Simeon,
              >
              I am reviewing this post in the newsgroup and would like to know the
              status
              of this issue.
              >
              If you have any question, please feel free to let me know.
              >
              Thank you for using our MSDN Managed Newsgroup Support Service!
              >
              Sincerely,
              Linda Liu
              Microsoft Online Community Support
              >
              Delighting our customers is our #1 priority. We welcome your comments and
              suggestions about how we can improve the support we provide to you. Please
              feel free to let my manager know what you think of the level of service
              provided. You can send feedback directly to my manager at:
              msdnmg@microsof t.com.
              >
              This posting is provided "AS IS" with no warranties, and confers no
              rights.
              >
              >

              Comment

              • =?Utf-8?B?Tmlja1I=?=

                #8
                RE: Find the Owner of a folder

                I have a question - What I really need is to get the Owner as a string so I
                can either display it in a label or write it to a textfile. But when I try
                the "Cstr" function on the NTAccount data type, i get a popup telling me it
                can't be converted.

                Is there any way to get the owner of a folder written to a string?

                "Linda Liu[MSFT]" wrote:
                Hi Simeon,
                >
                I am reviewing this post in the newsgroup and would like to know the status
                of this issue.
                >
                If you have any question, please feel free to let me know.
                >
                Thank you for using our MSDN Managed Newsgroup Support Service!
                >
                Sincerely,
                Linda Liu
                Microsoft Online Community Support
                >
                Delighting our customers is our #1 priority. We welcome your comments and
                suggestions about how we can improve the support we provide to you. Please
                feel free to let my manager know what you think of the level of service
                provided. You can send feedback directly to my manager at:
                msdnmg@microsof t.com.
                >
                This posting is provided "AS IS" with no warranties, and confers no rights.
                >
                >
                >

                Comment

                • kimiraikkonen

                  #9
                  Re: Find the Owner of a folder

                  On May 20, 12:09 am, NickR <Ni...@discussi ons.microsoft.c omwrote:
                  I have a question - What I really need is to get the Owner as a string so I
                  can either display it in a label or write it to a textfile. But when I try
                  the "Cstr" function on the NTAccount data type, i get a popup telling me it
                  can't be converted.
                  >
                  Is there any way to get the owner of a folder written to a string?
                  >
                  "Linda Liu[MSFT]" wrote:
                  Hi Simeon,
                  >
                  I am reviewing this post in the newsgroup and would like to know the status
                  of this issue.
                  >
                  If you have any question, please feel free to let me know.
                  >
                  Thank you for using our MSDN Managed Newsgroup Support Service!
                  >
                  Sincerely,
                  Linda Liu
                  Microsoft Online Community Support
                  >
                  Delighting our customers is our #1 priority. We welcome your comments and
                  suggestions about how we can improve the support we provide to you. Please
                  feel free to let my manager know what you think of the level of service
                  provided. You can send feedback directly to my manager at:
                  msd...@microsof t.com.
                  >
                  This posting is provided "AS IS" with no warranties, and confers no rights.
                  Just use "ToString" whenever you want to get owner as string:

                  Full edition:


                  Imports System.IO
                  Imports System.Security .AccessControl
                  Imports System.Security .Principal

                  Public Class Form1

                  Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
                  System.EventArg s) Handles MyBase.Load
                  Dim di As New DirectoryInfo(" directory_path" )
                  Dim ds As DirectorySecuri ty = di.GetAccessCon trol()
                  Dim owner As NTAccount = CType(ds.GetOwn er(GetType(NTAc count)),
                  NTAccount)
                  ' Show owner in messagebox as string
                  MsgBox(owner.To String)
                  ' or show in label as string
                  label1.text = owner.ToString
                  End Sub
                  End Class


                  Thanks,

                  Onur Güzel

                  Comment

                  • =?Utf-8?B?Tmlja1I=?=

                    #10
                    Re: Find the Owner of a folder

                    thanks, that function worked.
                    But, now i have another question if anyone cares to answer it.

                    I am running XP Pro (SP2) on my machine and our network is a Microsoft
                    Exchange Network.

                    Why is it that the owner for the folder using the code described above is
                    different than the one I get when I do a batch file using the dir command
                    with /q switch?

                    the dir /q command in DOS gives me the person who created it: DomainName\user

                    but he above code gives me BUILTIN\ADMINIS TRATORS

                    Any thoughts? Is more information?


                    "kimiraikko nen" wrote:
                    On May 20, 12:09 am, NickR <Ni...@discussi ons.microsoft.c omwrote:
                    I have a question - What I really need is to get the Owner as a string so I
                    can either display it in a label or write it to a textfile. But when I try
                    the "Cstr" function on the NTAccount data type, i get a popup telling me it
                    can't be converted.

                    Is there any way to get the owner of a folder written to a string?

                    "Linda Liu[MSFT]" wrote:
                    Hi Simeon,
                    I am reviewing this post in the newsgroup and would like to know the status
                    of this issue.
                    If you have any question, please feel free to let me know.
                    Thank you for using our MSDN Managed Newsgroup Support Service!
                    Sincerely,
                    Linda Liu
                    Microsoft Online Community Support
                    Delighting our customers is our #1 priority. We welcome your comments and
                    suggestions about how we can improve the support we provide to you. Please
                    feel free to let my manager know what you think of the level of service
                    provided. You can send feedback directly to my manager at:
                    msd...@microsof t.com.
                    This posting is provided "AS IS" with no warranties, and confers no rights.
                    >
                    Just use "ToString" whenever you want to get owner as string:
                    >
                    Full edition:
                    >
                    >
                    Imports System.IO
                    Imports System.Security .AccessControl
                    Imports System.Security .Principal
                    >
                    Public Class Form1
                    >
                    Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
                    System.EventArg s) Handles MyBase.Load
                    Dim di As New DirectoryInfo(" directory_path" )
                    Dim ds As DirectorySecuri ty = di.GetAccessCon trol()
                    Dim owner As NTAccount = CType(ds.GetOwn er(GetType(NTAc count)),
                    NTAccount)
                    ' Show owner in messagebox as string
                    MsgBox(owner.To String)
                    ' or show in label as string
                    label1.text = owner.ToString
                    End Sub
                    End Class
                    >
                    >
                    Thanks,
                    >
                    Onur Güzel
                    >

                    Comment

                    • =?Utf-8?B?Tmlja1I=?=

                      #11
                      Re: Find the Owner of a folder

                      Nevermind my last post. I figured out what was up.. I'm blind.

                      "NickR" wrote:
                      thanks, that function worked.
                      But, now i have another question if anyone cares to answer it.
                      >
                      I am running XP Pro (SP2) on my machine and our network is a Microsoft
                      Exchange Network.
                      >
                      Why is it that the owner for the folder using the code described above is
                      different than the one I get when I do a batch file using the dir command
                      with /q switch?
                      >
                      the dir /q command in DOS gives me the person who created it: DomainName\user
                      >
                      but he above code gives me BUILTIN\ADMINIS TRATORS
                      >
                      Any thoughts? Is more information?
                      >
                      >
                      "kimiraikko nen" wrote:
                      >
                      On May 20, 12:09 am, NickR <Ni...@discussi ons.microsoft.c omwrote:
                      I have a question - What I really need is to get the Owner as a string so I
                      can either display it in a label or write it to a textfile. But when I try
                      the "Cstr" function on the NTAccount data type, i get a popup telling me it
                      can't be converted.
                      >
                      Is there any way to get the owner of a folder written to a string?
                      >
                      "Linda Liu[MSFT]" wrote:
                      Hi Simeon,
                      >
                      I am reviewing this post in the newsgroup and would like to know the status
                      of this issue.
                      >
                      If you have any question, please feel free to let me know.
                      >
                      Thank you for using our MSDN Managed Newsgroup Support Service!
                      >
                      Sincerely,
                      Linda Liu
                      Microsoft Online Community Support
                      >
                      Delighting our customers is our #1 priority. We welcome your comments and
                      suggestions about how we can improve the support we provide to you. Please
                      feel free to let my manager know what you think of the level of service
                      provided. You can send feedback directly to my manager at:
                      msd...@microsof t.com.
                      >
                      This posting is provided "AS IS" with no warranties, and confers no rights.
                      Just use "ToString" whenever you want to get owner as string:

                      Full edition:


                      Imports System.IO
                      Imports System.Security .AccessControl
                      Imports System.Security .Principal

                      Public Class Form1

                      Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
                      System.EventArg s) Handles MyBase.Load
                      Dim di As New DirectoryInfo(" directory_path" )
                      Dim ds As DirectorySecuri ty = di.GetAccessCon trol()
                      Dim owner As NTAccount = CType(ds.GetOwn er(GetType(NTAc count)),
                      NTAccount)
                      ' Show owner in messagebox as string
                      MsgBox(owner.To String)
                      ' or show in label as string
                      label1.text = owner.ToString
                      End Sub
                      End Class


                      Thanks,

                      Onur Güzel

                      Comment

                      Working...