How can I convert from a SID to an account name in C#

后端 未结 10 1048
囚心锁ツ
囚心锁ツ 2020-12-01 02:56

I have a C# application that scans a directory and gathers some information. I would like to display the account name for each file. I can do this on the local system by g

10条回答
  •  鱼传尺愫
    2020-12-01 03:29

    Great. I cribbed some LookupAccountSid() code from here:

    http://www.pinvoke.net/default.aspx/advapi32.LookupAccountSid

    And that worked, though I had to provide the host name myself. In the case of a UNC path I can just take the first component of it. When it's a mapped drive, I use this code to convert the path to a UNC one:

    http://www.wiredprairie.us/blog/index.php/archives/22

    It seems to work, so that's how I'll do it, unless someone comes up with a situation in which the first component of a UNC path isn't the host name...

    Thank you all for your help.

提交回复
热议问题