Windows에 로그인한 계정이 마이크로소프트의 계정인지, 로컬 계정인지 알아내는 방법
찾아 보니 다음과 같은 글이 있습니다.
Get Microsoft Account Id from Windows 8 desktop application
; https://stackoverflow.com/questions/19740975/get-microsoft-account-id-from-windows-8-desktop-application
실제로 위의 Q&A에 나온 답변에 따라 다음과 같이 알아낼 수 있습니다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
public class Program
{
public static void Main(string[] args)
{
var wi = WindowsIdentity.GetCurrent();
var groups = from g in wi.Groups
select new SecurityIdentifier(g.Value)
.Translate(typeof(NTAccount)).Value;
var msAccount = (from g in groups
where g.StartsWith(@"MicrosoftAccount\")
select g).FirstOrDefault();
var test = msAccount == null ? wi.Name :
msAccount.Substring(@"MicrosoftAccount\".Length);
Console.WriteLine(test);
}
}
각각의 출력 유형은 다음과 같습니다.
[마이크로소프트 계정]
계정이 test@outlook.com이라면, 출력도 "test@outlook.com"
[로컬 컴퓨터 계정]
컴퓨터 명이 testpc, 사용자 계정이 tester라면 "TESTPC\tester"
[Active Directory 계정]
AD 명이 TEST.COM이고, 사용자 계정이 tester라면 "TEST.COM\tester"
[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]