David
发布于 2015-02-04 / 34 阅读 / 0 评论 / 0 点赞

C# 獲取系統當前登錄用戶SID

另外一篇文章中提到過用程序獲取,So
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            WindowsIdentity curUser = WindowsIdentity.GetCurrent();
            //用户SID
            SecurityIdentifier sid = curUser.User;
            //用户全名
            NTAccount ntacc = (NTAccount)sid.Translate(typeof(NTAccount));

            Console.WriteLine("用戶SID:{0} nr用戶全名:{1}", sid.Value, ntacc.Value);
            Console.ReadKey();
        }
    }
}