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

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

目次

Blog 利用状況

書庫

日記カテゴリ

DirectoryAccessクラスに追加したコンピュータ関連のメソッド

DirectoryAccess クラスに追加したコンピュータ関連のメソッドのコードです。

 

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

'コンピュータを取得します。

Public Shared Function GetComputers() As IList(Of Computer)

  Dim computers As New List(Of Computer)()

  Using root = GetRootEntry()   'ルートのDirectoryEntryを取得

    If CanConnectDomain Then  'ドメインに接続できる時

      Dim filter = String.Format("(objectCategory={0})", CategoryType.Computer)

      Using searcher As New DirectorySearcher(root, filter)

        Using results = searcher.FindAll()

          For Each res As SearchResult In results

            computers.Add(DirectCast(CreateInstance(res.GetDirectoryEntry()), Computer))

          Next

        End Using

      End Using

    End If

  End Using

  Return computers

End Function

 

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

//コンピュータを取得します。

public static IList<Computer> GetComputers()

{

  var computers = new List<Computer>();

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

  {

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

    {

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

      GroupTokens.Clear();

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

      {

        using (var results = searcher.FindAll())

        {

          foreach (SearchResult res in results)

          {

            computers.Add((Computer)CreateInstance(res.GetDirectoryEntry()));

          }

        }

      }

    }

  }

  return computers;

}

 

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

VB

Private Shared Function CreateInstance(entry As DirectoryEntry) As DirectoryObject

  Dim category As CategoryType

  If [Enum].TryParse(Of CategoryType)(entry.SchemaClassName, True, category) = False Then

    Throw New ArgumentException("entry の種類が CategoryType に該当しません。", "entry")

  End If

 

  Select Case category

    Case CategoryType.User

      If CanConnectDomain Then    'ドメインに接続できる時

        Return New DomainUser(entry)

      Else    'ドメインに接続できない時

        Return New LocalUser(entry)

      End If

    Case CategoryType.Group

      If CanConnectDomain Then    'ドメインに接続できる時

        Return New DomainGroup(entry)

      Else    'ドメインに接続できない時

        Return New LocalGroup(entry)

      End If

    Case CategoryType.Computer

      Return New Computer(entry)

    Case Else

      Throw New NotImplementedException()

  End Select

End Function

 

C#

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);

      }

    case CategoryType.Computer:

      return new Computer(entry);

    default:

      throw new NotImplementedException();

  }

}

投稿日時 : 2013年11月11日 19:42

コメントを追加

# re: DirectoryAccess????????????????????? 2021/08/07 17:59 hydroxychlor 200 mg

how does chloroquine work https://chloroquineorigin.com/# hydroxychloroqine

# doxycycline 100mg capsules https://doxycyline1st.com/
generic doxycycline 2022/02/26 8:28 Doxycycline

doxycycline 100mg capsules https://doxycyline1st.com/
generic doxycycline

# online doxycycline https://doxycyline1st.com/
where can i get doxycycline 2022/02/26 20:08 Doxycycline

online doxycycline https://doxycyline1st.com/
where can i get doxycycline

# hlhycwpdkgrw 2022/06/03 20:36 ksswotmv

http://erythromycin1m.com/# erythromycin for fish tanks

# Thanks for the good writeup. It actually was once a amusement account it. Look complicated to more added agreeable from you! By the way, how could we keep in touch? 2022/06/12 18:36 Thanks for the good writeup. It actually was once

Thanks for the good writeup. It actually was once a amusement account it.
Look complicated to more added agreeable from you!
By the way, how could we keep in touch?

# purchase prednisone no prescription https://prednisonepills.site/
prednisone 50 mg buy 2022/11/28 23:54 Prednisone

purchase prednisone no prescription https://prednisonepills.site/
prednisone 50 mg buy

# interracial dating central https://datingsiteonline.site/
singles sites 2022/12/05 23:50 Tading

interracial dating central https://datingsiteonline.site/
singles sites

# chloroquine online 2022/12/26 0:53 MorrisReaks

hydroxychloroquine online sale http://hydroxychloroquinex.com/

# new treatments for ed https://edpills.science/
cheap erectile dysfunction pills 2023/01/07 13:52 EdPills

new treatments for ed https://edpills.science/
cheap erectile dysfunction pills

# ed treatment pills https://edpill.pro/# - top rated ed pills 2023/06/27 10:19 EdPills

ed treatment pills https://edpill.pro/# - top rated ed pills

# buy prednisone 20mg without a prescription best price https://prednisone.bid/ prednisone 5mg capsules 2023/12/27 6:55 Prednisone

buy prednisone 20mg without a prescription best price https://prednisone.bid/ prednisone 5mg capsules

タイトル
名前
URL
コメント