zoukankan      html  css  js  c++  java
  • 代码记录

    在项目中遇到一个关于活动目录的一个问题先把代码粘贴如下,便于以后学习之用。
    using System;
    using System.DirectoryServices;

    namespace  G217010.Utility
    {
     /// <summary>
     /// CreatGroup の概要の説明です。
     /// 該当職員端末機が庁内ネットワークに接続する場合に対する操作を行います。
     /// </summary>
     public class CreatGroup
     {
      /// <summary>
      /// セキュリティグループ作り
      /// </summary>
      /// <param name="PCName"></param>
      /// <param name="GroupName"></param>
      /// <returns>存在と作りしました場合:true or 端末機が庁内ネットワークに接続していない場合false</returns>
      public bool CreatGrp(string PCName, string GroupName)
      {
       //
       // TODO: コンストラクタ ロジックをここに追加してください。
       //
       System.Diagnostics.Debug.WriteLine("START : CreatGroup - CreatGroup()");
          
       try
       {

        DirectoryEntry obDirEntry = null;
        DirectoryEntry adDirEntry = null;
        bool flag = false;
        adDirEntry = new DirectoryEntry("WinNT://PREF");
        //セキュリティグループ存在チェック
        foreach (DirectoryEntry i in adDirEntry.Children)
        {
         if (i.Name == "D" + GroupName)
         {
          flag = true;
          break;
         }

        }
        //存在しない場合
        if (!flag)
        {
         return false;
        }
        //Administratorsグループにセキュリティグループを登録する 
        obDirEntry = new DirectoryEntry("WinNT://" + PCName);
        DirectoryEntry AdGroup = obDirEntry.Children.Find("Administrators", "group");
        DirectoryEntry Group = adDirEntry.Children.Find("D" + GroupName, "group");

        //登録チェック。
        if ((bool)AdGroup.Invoke("IsMember", "WinNT://PREF/" + "D" + GroupName))
        {
         return true;
        }
        else
        {
         AdGroup.Invoke("Add", Group.Path.ToString());
         System.Diagnostics.Debug.WriteLine("END  : CreatGroup - CreatGroup()");
         return true;

        }
               
       }
       catch (Exception ex)
       {
              
        System.Diagnostics.Debug.WriteLine("END  : CreatGroup - CreatGroup()");
        throw ex;
        return false;
        
       }


      }
     }
    }

  • 相关阅读:
    结对编程队友个人项目分析
    Android入门3:从Toolbar到Material Design
    Qt串口通信
    AVT Vimba与OpenCV环境配置
    Git远程使用技巧
    Android入门2:从GridView控件使用到自定义Adapter
    Android入门1:使用VideoView和MediController播放视频
    kafka+spark streaming+redis学习
    kafka学习笔记
    安卓获取服务器返回的图片资源路径并下载图片
  • 原文地址:https://www.cnblogs.com/buaaliang/p/656781.html
Copyright © 2011-2022 走看看