タグ
  ANSI (1)
  ASP.NET (10)
  Active Directory (55)
  BAT (16)
  Backup (2)
  CSharp (11)
  CentOS (4)
  C言語 (4)
  DNS (4)
  Excel (2)
  FFmpeg (1)
  Fedora (4)
  FreeBSD (6)
  IPv6 (3)
  Java (11)
  JavaScript (8)
  LAN (1)
  Link (4)
  Linux (15)
  Mac (1)
  Mail (2)
  Microsoft (3)
  NIS (1)
  Node.js (6)
  OpenIndiana (1)
  OpenLDAP (2)
  OpenSSL (1)
  OpenSolaris (4)
  PHP (2)
  Perl (2)
  Postfix (1)
  PostgreSQL (2)
  PowerShell (34)
  RFC (3)
  SQL Server (5)
  Solaris (10)
  Ubuntu (9)
  VBScript (73)
  VCpp (2)
  VMware (3)
  Visual Basic (1)
  WMI (17)
  WSF (5)
  WSH (10)
  Windows (19)
  bash (1)
  bind (1)
  iSCSI (1)
  作成中 (8)
  慣用句 (3)
  正規表現 (6)
  運用 (8)
作成 2010.01.07
更新 2010.01.07
VBScript で Active Directory のオブジェクトSIDを取得する
このサンプルではstrDNに設定されたオブジェクトのSIDを表示します。
Option Explicit
Const adTypeBinary = 1
Const adTypeText   = 2
Const strDN = "CN=DC1,OU=Domain Controllers,DC=example,DC=lan"
' Const strDN = "CN=Administrator,CN=Users,DC=example,DC=lan"
Dim adObject, rawSID

On Error Resume Next
Set adObject = GetObject("LDAP://" & strDN )
If Err.Number <> 0 Then
  WScript.Echo strDN & " に接続できません"
  WScript.Quit
End If
On Error Goto 0

WScript.Echo GetStringSID( adObject )

Function GetStringSID( objAccount )
  Dim retStr, rawSID, arrSID
  Dim adStream, i, tmp, j
  retStr = "S-"
  rawSID = objAccount.Get( "objectSid" )

  Set adStream = WScript.CreateObject("ADODB.Stream")
  adStream.Type = adTypeText
  adStream.Charset = "UTF-16"
  adStream.Open
  adStream.WriteText rawSID
  adStream.Position = 0
  adStream.Type = adTypeBinary
  adStream.Position = 2
  ReDim arrSID(UBound(rawSID))

  For i=0 to UBound(rawSID)
    tmp = adStream.Read(1)
    If IsNull(tmp) Then Exit For
    arrSID(i) = AscB(tmp)
  Next
  adStream.Close

  retStr = retStr & arrSID(0) & "-" & arrSID(1)
  j = 3
  Do While UBound(arrSID) >= j * 4 - 1
    tmp = arrSID(j*4-1) * 256^3 + arrSID(j*4-2) * 256^2 + arrSID(j*4-3) * 256 + arrSID(j*4-4)
    j = j + 1
    retStr = retStr & "-" & tmp
  Loop

  GetStringSID = retStr
End Function
[リロード] [記事修正] [新規作成] [使用方法]
©2004-2012 UPKEN IPv4