システム開発 備忘録









システム開発備忘録 ユーザー情報取得(Active Directory)

*** *** *** *** ***


DirectoryEntryによる情報取得、ADからユーザー情報を取得する

'パス設定
Dim strDomain As String = System.Environment.UserDomainName 'ドメイン取得
Dim strUserName As String = System.Environment.UserName 'ユーザー取得
Dim strPath As String = "WinNT://" + strDomain + "/" + strUserName
'バインド
Dim DirEnt As System.DirectoryServices.DirectoryEntry = New System.DirectoryServices.DirectoryEntry(strPath)

'ユーザー名を取得する
Dim strFullName As String
strFullName = DirEnt.Properties.Item("FullName").Value
MsgBox("名前は" & strFullName & " です")

'DirectoryEntryのプロパティ一覧を表示する
For Each strPropertyName As String In DirEnt.Properties.PropertyNames
    Debug.Print(strPropertyName & "," & DirEnt.Properties.Item(strPropertyName).Value.ToString)
Next

'クローズ
DirEnt.Close()

Principalインターフェースで所属グループを確認する

'ログオンユーザーにバインドする
Dim principal As System.Security.Principal.WindowsPrincipal = New System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent())

'クライアント機のアドミニ権限があるか調べる
If (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) Then
    MsgBox("このコンピュータのAdmin権限があります。")
End If

'ドメインのアドミニ権限があるか調べる
If (principal.IsInRole("DomainName\Domain Admins")) Then
    MsgBox("Domain Admin権限があります。")
End If



Copyright (C) 2009- station-t.com All Rights Reserved , Link Free