函式內容與 http://tw.wingwit.com/Article/program/net/201311/14263.html  相同

 

附上詳細內容

using System;
using System.Security.Principal;

public static bool IsAdministrator()
{
   //回傳True表示為管理員身分;反之則非管理員
   WindowsIdentity identity = WindowsIdentity.GetCurrent();
   WindowsPrincipal principal = new WindowsPrincipal( identity );
   return principal.IsInRole( WindowsBuiltInRole.Administrator );
}


 

簡易使用範例:

if (IsAdministrator()==True)
{
    // do something
}
else
{
   // do others
}

 

arrow
arrow

    holmes310524 發表在 痞客邦 留言(0) 人氣()