マイナーでもいいよね??

殆どVB系、でも .NET じゃない VB は知らないよん

目次

Blog 利用状況

書庫

日記カテゴリ

DirectoryAccessクラスに追加したグループ関連のメソッド(C#)

DirectoryAccess クラスに追加したグループ関連のメソッドのC#のコードです。

前回追加したコードはこちら

 

//指定した ADSI オブジェクトの所属パスを取得します。

public static string GetBelongPath(IADs native)  //オーバーロードを追加

{

  if (entry == null)

  {

    throw new ArgumentNullException("native", "native が null です。");

  }

  return GetBelongPath(native.ADsPath);

}

 

//グループを取得を取得します。GroupTokens プロパティが設定されます。

public static IList GetGroups() where T : DirectoryObject, IGroup

{

  var groups = new List();

  using (var root = GetRootEntry())    //ルートのDirectoryEntryを取得

  {

    if (CanConnectDomain)    //ドメインに接続できる時

    {

      var filter = String.Format("(objectCategory={0})", CategoryType.Group);

      GroupTokens.Clear();

      using (var searcher = new DirectorySearcher(root, filter))

      {

        using (var results = searcher.FindAll())

        {

          foreach (SearchResult res in results)

          {

            var entry = res.GetDirectoryEntry();

            groups.Add((T)CreateInstance(entry));

            AddGroupToken(entry);   //PrimaryGroupTokenを追加

          }

        }

    }

    else    //ドメインに接続できない時  <-- こっちはローカル

    {

      root.Children.SchemaFilter.Add(CategoryType.Group.ToString());

      foreach (DirectoryEntry entry in root.Children)

      {

        groups.Add((T)CreateInstance(entry));

      }

    }

  }

  return groups;

}

 

//指定した PrimaryGroupToken を持つドメイングループをプライマリグループとしているメンバの DirectoryEntry のコレクションを取得します。

public static IList<DirectoryEntry> GetPrimaryGroupMemberEntries(int primaryGroupToken)

{

  if (CanConnectDomain == false//ドメインに接続できない時

  {

    return new List<DirectoryEntry>();

  }

 

  var entries = new List<DirectoryEntry>();

  using (var root = GetRootEntry())    //ルートのDirectoryEntryを取得

  {

    var filter = String.Format("(&(|(objectCategory={0})(objectCategory={1}))(primaryGroupID={2}))",

      CategoryType.User, CategoryType.Computer, primaryGroupToken);

    using (var searcher = new DirectorySearcher(root, filter))

    {

      using (var results = searcher.FindAll())

      {

        foreach (SearchResult res in results)

        {

          entries.Add(res.GetDirectoryEntry());

        }

      }

    }

  }

  return entries;

}

 

//指定した LDAP パスの名前(オブジェクト名)を取得します。

public static string PathToCn(string ldapPath)

{

  if (ldapPath == null)

  {

    throw new ArgumentNullException("ldapPath", "ldapPath が null です。");

  }

 

  var spos = ldapPath.IndexOf('=') + 1;

  if (spos == 0)

  {

    return ldapPath;

  }

 

  var epos = ldapPath.IndexOf(',');

  if (spos > 0)

  {

    return ldapPath.Substring(spos, epos - spos);

  }

  else

  {

    return ldapPath.Substring(spos);

  }

}

 

//PrimaryGroupToken を追加します。

private static void AddGroupToken(DirectoryEntry entry)

{

  entry.Invoke("GetInfoEx", new object[] { "primaryGroupToken" }, 0);

  var token = Convert.ToInt32(entry.Properties["primaryGroupToken"].Value);

  GroupTokens.Add(token, entry.Properties["cn"].Value.ToString());

}

 

DirectoryObject のインスタンスを作成する CreateInstance メソッドにグループ部分のコード(太字の部分)を追加しました。

private static DirectoryObject CreateInstance(DirectoryEntry entry)

{

  CategoryType category;

  if (Enum.TryParse<CategoryType>(entry.SchemaClassName, true, out category) == false)

  {

    throw new ArgumentException("entry の種類が CategoryType に該当しません。", "entry");

  }

 

  switch (category)

  {

    case CategoryType.User:

      if (CanConnectDomain)    //ドメインに接続できる時

      {

        return new DomainUser(entry);

      }

      else    //ドメインに接続できない時

      {

        return new LocalUser(entry);

      }

    case CategoryType.Group:

      if (CanConnectDomain)    //ドメインに接続できる時

      {

        return new DomainGroup(entry);

      }

      else    //ドメインに接続できない時

      {

        return new LocalGroup(entry);

      }

    default:

      throw new NotImplementedException();

  }

}

投稿日時 : 2013年8月23日 23:58

コメントを追加

# What's up i am kavin, its my first occasion to commenting anywhere, when i read this post i thought i could also create comment due to this sensible piece of writing. 2019/06/02 8:13 What's up i am kavin, its my first occasion to com

What's up i am kavin, its my first occasion to commenting anywhere, when i
read this post i thought i could also create comment due to this
sensible piece of writing.

# Hi, I do think this is an excellent web site. I stumbledupon it ;) I will come back yet again since I book marked it. Money and freedom is the best way to change, may you be rich and continue to help other people. 2019/06/03 20:34 Hi, I do think this is an excellent web site. I s

Hi, I do think this is an excellent web site. I stumbledupon it ;) I will come back yet again since I book marked it.
Money and freedom is the best way to change, may you be rich and continue to help other people.

# I don't even know how I ended up here, but I thought this post was good. I do not know who you are but definitely you're going to a famous blogger if you are not already ;) Cheers! 2019/07/24 14:31 I don't even know how I ended up here, but I thoug

I don't even know how I ended up here, but I thought this post was good.
I do not know who you are but definitely you're going to a famous blogger if you are
not already ;) Cheers!

# I don't even know how I ended up here, but I thought this post was good. I do not know who you are but definitely you're going to a famous blogger if you are not already ;) Cheers! 2019/07/24 14:32 I don't even know how I ended up here, but I thoug

I don't even know how I ended up here, but I thought this post was good.
I do not know who you are but definitely you're going to a famous blogger if you are
not already ;) Cheers!

# I don't even know how I ended up here, but I thought this post was good. I do not know who you are but definitely you're going to a famous blogger if you are not already ;) Cheers! 2019/07/24 14:33 I don't even know how I ended up here, but I thoug

I don't even know how I ended up here, but I thought this post was good.
I do not know who you are but definitely you're going to a famous blogger if you are
not already ;) Cheers!

# I don't even know how I ended up here, but I thought this post was good. I do not know who you are but definitely you're going to a famous blogger if you are not already ;) Cheers! 2019/07/24 14:34 I don't even know how I ended up here, but I thoug

I don't even know how I ended up here, but I thought this post was good.
I do not know who you are but definitely you're going to a famous blogger if you are
not already ;) Cheers!

# Very energetic blog, I enjoyed that a lot. Will there be a part 2? 2019/08/15 5:25 Very energetic blog, I enjoyed that a lot. Will th

Very energetic blog, I enjoyed that a lot. Will there be a part 2?

# Have you ever considered about adding a little bit more than just your articles? I mean, what you say is valuable and all. However imagine if you added some great visuals or video clips to give your posts more, "pop"! Your content is excellent b 2019/09/03 15:41 Have you ever considered about adding a little bit

Have you ever considered about adding a little bit more than just your articles?
I mean, what you say is valuable and all.
However imagine if you added some great visuals or video clips to give your posts more, "pop"!
Your content is excellent but with images and videos, this website could certainly be one of the greatest in its niche.

Good blog!

# Have you ever considered about adding a little bit more than just your articles? I mean, what you say is valuable and all. However imagine if you added some great visuals or video clips to give your posts more, "pop"! Your content is excellent b 2019/09/03 15:42 Have you ever considered about adding a little bit

Have you ever considered about adding a little bit more than just your articles?
I mean, what you say is valuable and all.
However imagine if you added some great visuals or video clips to give your posts more, "pop"!
Your content is excellent but with images and videos, this website could certainly be one of the greatest in its niche.

Good blog!

# Have you ever considered about adding a little bit more than just your articles? I mean, what you say is valuable and all. However imagine if you added some great visuals or video clips to give your posts more, "pop"! Your content is excellent b 2019/09/03 15:43 Have you ever considered about adding a little bit

Have you ever considered about adding a little bit more than just your articles?
I mean, what you say is valuable and all.
However imagine if you added some great visuals or video clips to give your posts more, "pop"!
Your content is excellent but with images and videos, this website could certainly be one of the greatest in its niche.

Good blog!

# Have you ever considered about adding a little bit more than just your articles? I mean, what you say is valuable and all. However imagine if you added some great visuals or video clips to give your posts more, "pop"! Your content is excellent b 2019/09/03 15:44 Have you ever considered about adding a little bit

Have you ever considered about adding a little bit more than just your articles?
I mean, what you say is valuable and all.
However imagine if you added some great visuals or video clips to give your posts more, "pop"!
Your content is excellent but with images and videos, this website could certainly be one of the greatest in its niche.

Good blog!

# nqwlQCBVChzdxxb 2021/07/03 2:54 https://amzn.to/365xyVY

Major thankies for the blog post.Thanks Again. Great.

# re: DirectoryAccess???????????????????(C#) 2021/08/08 15:57 hydroxychloroquine for malaria

choloroquine https://chloroquineorigin.com/# hydroxy cloroquine

# oxtxdcldtxxx 2021/11/28 1:49 dwedaydldy

https://chloroquinesab.com/

# ivermectin lotion cost http://stromectolabc.com/
ivermectin purchase 2022/02/08 2:46 Busjdhj

ivermectin lotion cost http://stromectolabc.com/
ivermectin purchase

# fdswixzjwwuf 2022/05/08 21:24 wlsvhd

hydroxocloroquine https://keys-chloroquineclinique.com/

# prednisone sale https://prednisone20mg.site/
prednisone drug costs 2022/11/15 17:55 Prednisone

prednisone sale https://prednisone20mg.site/
prednisone drug costs

# purchase chloroquine online 2022/12/30 0:15 MorrisReaks

chloroquine over the counter uk http://www.hydroxychloroquinex.com/#

# doors2.txt;1 2023/03/14 16:21 LClpJjLUXPpDOgynmY

doors2.txt;1

# prednisone in india - https://prednisonesale.pro/# 2023/04/22 15:21 Prednisone

prednisone in india - https://prednisonesale.pro/#

# canadian prescriptions online https://pillswithoutprescription.pro/# 2023/05/14 22:11 PillsPresc

canadian prescriptions online https://pillswithoutprescription.pro/#

# erection pills that work: https://edpills.pro/# 2023/05/16 3:32 EdPillsPro

erection pills that work: https://edpills.pro/#

# prednisone in uk https://prednisonepills.pro/# - prednisone 60 mg price 2023/06/05 5:27 Prednisone

prednisone in uk https://prednisonepills.pro/# - prednisone 60 mg price

# ï»¿paxlovid https://paxlovid.pro/# - paxlovid for sale 2023/07/03 4:11 Paxlovid

paxlovid https://paxlovid.pro/# - paxlovid for sale

# ed pills online https://edpills.ink/# - ed remedies 2023/07/26 20:03 EdPills

ed pills online https://edpills.ink/# - ed remedies

# versandapotheke deutschland 2023/09/26 12:03 Williamreomo

http://onlineapotheke.tech/# online apotheke deutschland
online apotheke gГ?nstig

# online apotheke gГјnstig 2023/09/27 1:17 Williamreomo

https://onlineapotheke.tech/# gГ?nstige online apotheke
п»?online apotheke

# internet apotheke 2023/09/27 2:24 Williamreomo

https://onlineapotheke.tech/# versandapotheke deutschland
versandapotheke deutschland

# gГјnstige online apotheke 2023/09/27 6:17 Williamreomo

https://onlineapotheke.tech/# online apotheke gГ?nstig
versandapotheke

# online apotheke preisvergleich 2023/09/27 10:25 Williamreomo

https://onlineapotheke.tech/# versandapotheke versandkostenfrei
gГ?nstige online apotheke

# comprare farmaci online all'estero 2023/09/27 17:17 Rickeyrof

acheter sildenafil 100mg sans ordonnance

# п»їfarmacia online migliore 2023/09/27 19:40 Rickeyrof

acheter sildenafil 100mg sans ordonnance

# п»їfarmacia online migliore 2023/09/27 19:57 Rickeyrof

acheter sildenafil 100mg sans ordonnance

# ed remedies https://edpillsotc.store/# - best male enhancement pills 2023/10/07 21:15 EdPills

ed remedies https://edpillsotc.store/# - best male enhancement pills

# canadian pharmacies that ship to the us 2023/10/16 13:00 Dannyhealm

They always have the newest products on the market. https://mexicanpharmonline.shop/# mexican border pharmacies shipping to usa

# online doctor prescription canada 2023/10/16 13:58 Dannyhealm

The team always ensures that I understand my medication fully. https://mexicanpharmonline.com/# pharmacies in mexico that ship to usa

# mexican mail order pharmacies 2023/10/16 16:53 Dannyhealm

Their health seminars are always enlightening. https://mexicanpharmonline.shop/# reputable mexican pharmacies online

# rx from canada 2023/10/16 17:52 Dannyhealm

I'm always informed about potential medication interactions. http://mexicanpharmonline.com/# pharmacies in mexico that ship to usa

# buy prescription online 2023/10/17 10:46 Dannyhealm

They bridge global healthcare gaps seamlessly. http://mexicanpharmonline.shop/# reputable mexican pharmacies online

# candaian pharmacies 2023/10/18 0:23 Dannyhealm

They always have valuable advice on medication management. http://mexicanpharmonline.com/# mexican border pharmacies shipping to usa

# canada pharmcy 2023/10/18 2:06 Dannyhealm

The staff ensures a seamless experience every time. https://mexicanpharmonline.com/# mexico drug stores pharmacies

# paxlovid cost without insurance 2023/12/01 7:47 Mathewhip

paxlovid generic http://paxlovid.club/# buy paxlovid online

# canadian internet pharmacies 2023/12/01 21:27 MichaelBum

http://paxlovid.club/# п»?paxlovid

# canadian drug prices 2023/12/02 12:22 MichaelBum

https://paxlovid.club/# Paxlovid buy online

# farmacias online seguras 2023/12/07 14:21 RonnieCag

http://tadalafilo.pro/# farmacia online

# farmacia online madrid 2023/12/07 17:21 RonnieCag

https://tadalafilo.pro/# farmacia online madrid

# farmacia online envío gratis 2023/12/07 20:35 RonnieCag

http://tadalafilo.pro/# farmacias online seguras en españa

# farmacia online barata 2023/12/08 5:57 RonnieCag

http://vardenafilo.icu/# farmacias baratas online envío gratis

# farmacia envíos internacionales 2023/12/08 14:24 RonnieCag

http://vardenafilo.icu/# farmacias online seguras en españa

# farmacia online envío gratis 2023/12/08 17:21 RonnieCag

https://tadalafilo.pro/# farmacia envíos internacionales

# farmacia online envío gratis 2023/12/09 12:06 RonnieCag

https://farmacia.best/# farmacia barata

# farmacias baratas online envío gratis 2023/12/09 21:30 RonnieCag

https://tadalafilo.pro/# farmacia 24h

# farmacia online 24 horas 2023/12/10 11:08 RonnieCag

http://farmacia.best/# farmacia online barata

# farmacias online seguras en españa 2023/12/10 14:05 RonnieCag

https://vardenafilo.icu/# farmacias online seguras en españa

# ï»¿farmacia online 2023/12/10 17:14 RonnieCag

https://tadalafilo.pro/# farmacia barata

# ï»¿farmacia online 2023/12/11 4:36 RonnieCag

http://tadalafilo.pro/# farmacia online

# farmacia envíos internacionales 2023/12/12 21:55 RonnieCag

http://vardenafilo.icu/# farmacia 24h

# farmacias online baratas 2023/12/13 11:37 RonnieCag

http://tadalafilo.pro/# farmacia online 24 horas

# sweetie fox new https://sweetiefox.pro/ - sweetie fox
2024/03/06 17:33 SwitieFox

sweetie fox new https://sweetiefox.pro/ - sweetie fox

# sweet bonanza free spin demo https://sweetbonanza.bid/ - sweet bonanza demo t&#252;rk&#231;e
2024/03/27 22:11 Bonanzaj

sweet bonanza free spin demo https://sweetbonanza.bid/ - sweet bonanza demo t&#252;rk&#231;e

# cytotec buy online usa https://cytotec.club/ Abortion pills online 2024/04/27 21:51 Cytotec

cytotec buy online usa https://cytotec.club/ Abortion pills online

タイトル
名前
URL
コメント