次の方法で共有


ADSI プロパティの呼び出し

ADSI COM オブジェクトのプロパティは、2 つの方法のいずれかで直接アクセスできます。1 つは、InvokeMember メソッドを使用する方法です。もう 1 つは、InvokeGet および InvokeSet メソッドを使用する方法です。これらは Microsoft .NET Framework Version 2.0 の新しいメソッドです。

次の C# の例は、InvokeMember メソッドを使用して、マネージ コード アプリケーションから IADSUser プロパティ、FirstName プロパティ、および LastName プロパティを取得する方法を示しています。これらのプロパティの詳細については、MSDN ライブラリ (https://go.microsoft.com/fwlink/?LinkID=27252) で IADsUser、FirstName、および LastName に関するページを参照してください。

using System.Reflection;
using System.DirectoryServices;

DirectoryEntry ent = new DirectoryEntry("LDAP://CN=My User,DC=Fabrikam,DC=com");
Object ads = ent.NativeObject;
Type type = ads.GetType();
String firstName = (string)type.InvokeMember(
    "FirstName", 
    BindingFlags.GetProperty, 
    null, 
    ads, 
    null);
String lastName = (string)type.InvokeMember(
    "LastName", 
    BindingFlags.GetProperty, 
    null, 
    ads, 
    null);

次の Visual Basic の例は、InvokeMember メソッドを使用して、マネージ コード アプリケーションから IADSUser プロパティ、FirstName プロパティ、および LastName プロパティを取得する方法を示しています。これらのプロパティの詳細については、MSDN ライブラリ (https://go.microsoft.com/fwlink/?LinkID=27252) で IADsUser、FirstName、および LastName に関するページを参照してください。

Imports System.Reflection
Imports System.DirectoryServices

Dim ent As New DirectoryEntry("LDAP://CN=My User,DC=Fabrikam,DC=com")
Dim ads As [Object] = ent.NativeObject
Dim type As Type = ads.GetType()
Dim firstName As String = CStr(type.InvokeMember( _
    "FirstName", _
    BindingFlags.GetProperty, _
    Nothing, _
    ads, _
    Nothing))
Dim lastName As String = CStr(type.InvokeMember( _
    "LastName", _
    BindingFlags.GetProperty, _
    Nothing, _
    ads, _
    Nothing))

次の C# の例は、InvokeGet メソッドを使用して、マネージ コード アプリケーションから IADSUser プロパティ、FirstName プロパティ、および LastName プロパティを取得する方法を示しています。これらのプロパティの詳細については、MSDN ライブラリ (https://go.microsoft.com/fwlink/?LinkID=27252) で IADsUser、FirstName、および LastName に関するページを参照してください。

.

using System.DirectoryServices;

DirectoryEntry ent = new DirectoryEntry("LDAP://CN=My User,DC=Fabrikam,DC=com");
String firstName = (string)ent.InvokeGet("FirstName");
String lastName = (string)ent.InvokeGet("LastName");

次の Visual Basic の例は、InvokeGet メソッドを使用して、マネージ コード アプリケーションから IADSUser プロパティ、FirstName プロパティ、および LastName プロパティを取得する方法を示しています。これらのプロパティの詳細については、MSDN ライブラリ (https://go.microsoft.com/fwlink/?LinkID=27252) で IADsUser、FirstName、および LastName に関するページを参照してください。

Imports System.DirectoryServices

Dim ent As New DirectoryEntry("LDAP://CN=My User,DC=Fabrikam,DC=com")
Dim firstName As String = CStr(ent.InvokeGet("FirstName"))
Dim lastName As String = CStr(ent.InvokeGet("LastName"))

次の C# の例は、InvokeMember メソッドを使用してオブジェクトの Description プロパティを設定する方法を示しています。

using System.Reflection;
using System.DirectoryServices;

DirectoryEntry ent = new DirectoryEntry("LDAP://CN=My User,DC=Fabrikam,DC=com");
Object ads = ent.NativeObject;
Type type = ads.GetType();
type.InvokeMember("Description", 
    BindingFlags.SetProperty, 
    null, 
    ads, 
    new object[] {"some description"});

// The changes to the object must always be committed or else they 
// will be lost.
ent.CommitChanges(); 

次の Visual Basic の例は、InvokeMember メソッドを使用してオブジェクトの Description プロパティを設定する方法を示しています。

Imports System.Reflection
Imports System.DirectoryServices

Dim ent As New DirectoryEntry("LDAP://CN=My User,DC=Fabrikam,DC=com")
Dim ads As [Object] = ent.NativeObject
Dim type As Type = ads.GetType()
type.InvokeMember("Description", _
    BindingFlags.SetProperty, _
    Nothing, _
    ads, _
    New Object() {"some description"})

' The changes to the object must always be committed or else they 
' will be lost.
ent.CommitChanges()

次の C# の例は、InvokeSet メソッドを使用してディレクトリ エントリの Description プロパティを設定する方法を示しています。Description プロパティの詳細については、MSDN ライブラリ (https://go.microsoft.com/fwlink/?LinkID=27252) で Description に関するページを参照してください。

using System.DirectoryServices;

DirectoryEntry ent = new DirectoryEntry("LDAP://CN=My User,DC=Fabrikam,DC=com");
ent.InvokeSet("Description", new object[] {"some description"});

// The changes to the object must always be committed or else they 
// will be lost.
ent.CommitChanges();

次の Visual Basic の例は、InvokeSet メソッドを使用してディレクトリ エントリの Description プロパティを設定する方法を示しています。Description プロパティの詳細については、MSDN ライブラリ (https://go.microsoft.com/fwlink/?LinkID=27252) で Description に関するページを参照してください。

Imports System.DirectoryServices

Dim ent As New DirectoryEntry("LDAP://CN=My User,DC=Fabrikam,DC=com")
ent.InvokeSet("Description", New Object() {"some description"})

' The changes to the object must always be committed or else they 
' will be lost.
ent.CommitChanges()

関連項目

リファレンス

System.DirectoryServices
DirectoryEntry
Type

概念

ADSI の呼び出し

Send comments about this topic to Microsoft.

Copyright © 2007 by Microsoft Corporation. All rights reserved.