欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#实现判断当前操作用户管理角色的方法

程序员文章站 2023-11-27 23:50:04
本文实例讲述了c#实现判断当前操作用户管理角色的方法。分享给大家供大家参考。具体实现方法如下: /// /// 判断当前操作用户...

本文实例讲述了c#实现判断当前操作用户管理角色的方法。分享给大家供大家参考。具体实现方法如下:

/// <summary>
/// 判断当前操作用户的管理角色
/// </summary>
public static void getcurrentuserrole()
{
  appdomain appdomain = system.threading.thread.getdomain();
  appdomain.setprincipalpolicy(system.security.principal.principalpolicy.windowsprincipal);
  system.security.principal.windowsprincipal wp = system.threading.thread.currentprincipal as system.security.principal.windowsprincipal;
  bool isuser = wp.isinrole(system.security.principal.windowsbuiltinrole.guest);
  console.write("当前用户的角色是:");
  if (isuser)
    console.writeline("来宾");
  isuser = wp.isinrole(system.security.principal.windowsbuiltinrole.user);
  if (isuser)
    console.writeline("普通用户");
  isuser = wp.isinrole(system.security.principal.windowsbuiltinrole.poweruser);
  if (isuser)
    console.writeline("超级用户");
  isuser = wp.isinrole(system.security.principal.windowsbuiltinrole.administrator);
  if (isuser)
    console.writeline("系统管理员");
  isuser = wp.isinrole(system.security.principal.windowsbuiltinrole.systemoperator);
  if (isuser)
    console.writeline("系统操作员");
  isuser = wp.isinrole(system.security.principal.windowsbuiltinrole.backupoperator);
  if (isuser)
    console.writeline("备份操作员");
  isuser = wp.isinrole(system.security.principal.windowsbuiltinrole.printoperator);
  if (isuser)
    console.writeline("打印操作员");
  isuser = wp.isinrole(system.security.principal.windowsbuiltinrole.accountoperator);
  if (isuser)
    console.writeline("账户操作员");
  isuser = wp.isinrole(system.security.principal.windowsbuiltinrole.replicator);
  if (isuser)
    console.writeline("复制程序员");
}

希望本文所述对大家的c#程序设计有所帮助。