{"id":2669,"date":"2011-12-22T00:54:28","date_gmt":"2011-12-21T15:54:28","guid":{"rendered":"http:\/\/www.moonmile.net\/blog\/archives\/2669"},"modified":"2011-12-22T12:24:06","modified_gmt":"2011-12-22T03:24:06","slug":"active-directory-%e3%81%af-directoryentry-%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e6%a4%9c%e7%b4%a2%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"http:\/\/www.moonmile.net\/blog\/archives\/2669","title":{"rendered":"Active Directory \u306f DirectoryEntry \u3092\u4f7f\u3063\u3066\u691c\u7d22\u3059\u308b"},"content":{"rendered":"<p>\n.NET \u3067\u3001\u30c9\u30e1\u30a4\u30f3\u30b5\u30fc\u30d0\u30fc\u306b\u3042\u308b\u60c5\u5831\u3092\u691c\u7d22\u3059\u308b\u306b\u306f\u30013 \u3064\u306e\u30af\u30e9\u30b9\u3092\u99c6\u4f7f\u3057\u307e\u3059\u3002\n<\/p>\n<ul>\n<li>DirectoryEntry \u30af\u30e9\u30b9\uff1a \u30a8\u30f3\u30c8\u30ea\u305d\u306e\u3082\u306e<\/li>\n<li>DirectorySearcher \u30af\u30e9\u30b9\uff1a LDAP \u30af\u30a8\u30ea\u3067\u691c\u7d22<\/li>\n<li>SearchResult \u30af\u30e9\u30b9\uff1a DirectorySearcher \u3067\u691c\u7d22\u3057\u305f\u7d50\u679c<\/li>\n<\/ul>\n<p>\n\u3042\u3068\u306f\u3001DirectoryEntry \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e Properties \u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092\u4f7f\u3048\u3070\u3001\u306a\u3093\u3068\u304b\u306a\u308b\u306e\u3067\u3059\u304c&#8230;\u7d50\u69cb\u3001\u3053\u308c\u304c\u6163\u308c\u308b\u307e\u3067\u304c\u5927\u5909\u306a\u306e\u3067\u3001\u30e1\u30e2\u304c\u3066\u3089\u516c\u958b\u3057\u3066\u304a\u304d\u307e\u3059\u3002\n<\/p>\n<p>\n# \u4e8b\u60c5\u304c\u3042\u3063\u3066\u3001\u30b3\u30fc\u30c9\u306f VB \u3067\u3002\n<\/p>\n<p>\n\u25a0\u30c9\u30e1\u30a4\u30f3\u69cb\u6210\u3068\u554f\u984c\n<\/p>\n<p>\n\u30c9\u30e1\u30a4\u30f3\u69cb\u6210\u306f\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002\n<\/p>\n<p><a href='http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/12\/wpid-dworkblogimage20111221_02org.jpg'><img border='0' src='http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/12\/wpid-dworkblogimage20111221_02thum.jpg'\/><\/a><\/p>\n<p>\n\u8a33\u3042\u3063\u3066\u3001\u30c9\u30e1\u30a4\u30f3\u30b5\u30fc\u30d0\u30fc\u304c2\u3064\u3042\u308a\u307e\u3059\u3002\u901a\u5e38\u3001\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u307b\u3046\u306f\u3001plan.local \u30c9\u30e1\u30a4\u30f3\u306a\u306e\u3067\u3059\u304c\u3001\u30b0\u30eb\u30fc\u30d7\u306e\u8a2d\u5b9a\u3084\u3089\u306a\u306b\u3084\u3089\u304c\u3042\u308b\u306e\u306f\u3001moonmile.local \u30c9\u30e1\u30a4\u30f3\u306e\u307b\u3046\u306a\u306e\u3067\u3059\u3002\u307e\u3041\u3001\u901a\u5e38\u696d\u52d9\u306e\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\uff08\u6587\u66f8\u95b2\u89a7\u3068\u304b\uff09\u306f plan.local \u30c9\u30e1\u30a4\u30f3\u3067\u884c\u3063\u3066\u3044\u3066\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u7d61\u307f\u306e\u3084\u3084\u3053\u3057\u3044\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u95a2\u4fc2\u306f moonmile.local \u306b\u9589\u3058\u8fbc\u3081\u305f\u3001\u3068\u8003\u3048\u3066\u304f\u3060\u3055\u3044\u3002\n<\/p>\n<p>\n\u3053\u3053\u3067\u3001tomoaki@plan.local \u306e\u30e6\u30fc\u30b6\u30fc\u304c\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3044\u308b\u3068\u304d\u306b\u3001GRP001 \u306a\u3069\u306e\u30b0\u30eb\u30fc\u30d7\u306b\u5c5e\u3057\u3066\u3044\u308b\u304b\uff1f\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3001\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\n<\/p>\n<p>\n\u666e\u901a\u306a\u3089\u3070\u3001plan.local \u306e\u307b\u3046\u306b\u30b0\u30eb\u30fc\u30d7\u3092\u4f5c\u308c\u3070\u3044\u3044\u306e\u3067\u3059\u304c&#8230;\u305d\u3053\u306f\u696d\u52d9\u7684\u306a\u5236\u9650\u3067\u3059\u3002\n<\/p>\n<p>\n\u25a0\u30e6\u30fc\u30b6\u30fc\u3068\u30b0\u30eb\u30fc\u30d7\u306e\u8a2d\u5b9a\n<\/p>\n<p>\n\u5b9f\u9a13\u7684\u306b\u3001windows server 2008 R2 \u3092\u4f7f\u3063\u3066\u3001\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002\n<\/p>\n<p><a href='http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/12\/wpid-dworkblogimage20111221_03org.jpg'><img border='0' src='http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/12\/wpid-dworkblogimage20111221_03thum.jpg'\/><\/a><\/p>\n<p>\ntomoaki@plan.local \u30e6\u30fc\u30b6\u30fc\u3092\u3001\u3069\u306e\u3088\u3046\u306b\u3057\u3066 moonmile.local \u306e\u307b\u3046\u306b\u6f5c\u308a\u8fbc\u307e\u305b\u308b\u304b\u3068\u3044\u3046\u3068\u3001tomoaki@plan.local \u306e SID \u3092\u4f7f\u3063\u305f\u30e6\u30fc\u30b6\u30fc\u3092 moonmile.local \u306b\u4f5c\u6210\u3057\u307e\u3059\u3002\n<\/p>\n<p><a href='http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/12\/wpid-dworkblogimage20111221_04org.jpg'><img border='0' src='http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/12\/wpid-dworkblogimage20111221_04thum.jpg'\/><\/a><\/p>\n<p>\n\u3053\u308c\u3092 moonmile.local \u30c9\u30e1\u30a4\u30f3\u5185\u3067\u691c\u7d22\u3057\u3066\u3001\u30b0\u30eb\u30fc\u30d7\u306b\u5165\u3063\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3088\u3046\u3068\u3044\u3046\u4ed5\u7d44\u307f\u3067\u3059\u3002<br \/>\nForeignSecurityPrincipals \u306e\u307b\u3046\u306b\u5165\u308c\u3066\u3044\u308b\u306e\u306f\u3001SID \u3092\u516c\u958b\u3057\u3066\u3044\u308b\u304b\u3001\u4e00\u5fdc\u3001\u3063\u3066\u3053\u3068\u3067\u3059\u306d\u3002\u672c\u6765\u306a\u3089\u3070\u3001moonmile.local \u3068 plan.local \u306e SID \u3092\u540c\u3058\u3082\u306e\u306b\u3059\u308c\u3070\u8a71\u306f\u7c21\u5358\u306a\u306e\u3067\u3059\u304c\u3001<b>\u4f5c\u308a\u65b9\u304c\u5206\u304b\u3089\u306a\u3044<\/b>\uff08\u82e6\u7b11\uff09\u306e\u3067\u3001\u5225\u3005\u306e SID \u306b\u306a\u308a\u307e\u3059\u3002\n<\/p>\n<p><a href='http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/12\/wpid-dworkblogimage20111221_06org.jpg'><img border='0' src='http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/12\/wpid-dworkblogimage20111221_06thum.jpg'\/><\/a><br \/>\n<a href='http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/12\/wpid-dworkblogimage20111221_07org.jpg'><img border='0' src='http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/12\/wpid-dworkblogimage20111221_07thum.jpg'\/><\/a><\/p>\n<p>\nSID \u81ea\u4f53\u3092\u30e6\u30fc\u30b6\u30fc\u540d\u306b\u3057\u3066\u3044\u307e\u3044\u307e\u3059\u3002windows server 2008 R2 \u3060\u3068\u3001SID \u306e\u9577\u3055\u306e\u307e\u307e\u3060\u3068\u5f8c\u308d\u306e\u307b\u3046\u304c\u5207\u308c\u3066\u3057\u307e\u3046\u306e\u3067\u3001\u5b9f\u969b\u306b\u691c\u7d22\u3059\u308b\u306e\u306f\u8868\u793a\u540d\uff08displayName\uff09\u306b\u306a\u308a\u307e\u3059\u3002\n<\/p>\n<p>\n\u25a0\u5b9f\u9a13\u958b\u59cb\n<\/p>\n<p>\n\u5c11\u3057\u305a\u3064\u4f5c\u3063\u3066\u3044\u308b\/\u4f5c\u3063\u305f\u306e\u3067\u3001\u30dc\u30bf\u30f3\u304c4\u3064\u3042\u308a\u307e\u3059\u3002\n<\/p>\n<p><a href='http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/12\/wpid-dworkblogimage20111222_01org.jpg'><img border='0' src='http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/12\/wpid-dworkblogimage20111222_01thum.jpg'\/><\/a><\/p>\n<ul>\n<li>AD \u691c\u7d22\uff08\u5168\u691c\u7d22\uff09: \u3072\u3068\u307e\u305a\u3001\u5168\u691c\u7d22\u3057\u3066\u307f\u308b\u3002<\/li>\n<li>ForeignSecurityPrincipals: CN \u3092\u6307\u5b9a\u3057\u3066\u3001\u7d5e\u3063\u3066\u307f\u308b\u3002<\/li>\n<li>ad-sv \u554f\u5408\u305b: tomoaki \u30e6\u30fc\u30b6\u30fc\u304c\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u307b\u3046\u3067\u3001SID \u3092\u53d6\u5f97\u3057\u307e\u3059\uff08\u5b9f\u969b\u306f\u3001\u30c9\u30e1\u30a4\u30f3\u306e\u30e6\u30fc\u30b6\u30fc \u3067\u3001WindowsIdentity.GetCurrent().User \u306e\u3088\u3046\u306b SID \u304c\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/li>\n<li>win2008-sv \u554f\u5408\u305b: \u30b0\u30eb\u30fc\u30d7\u540d\u307e\u3067\u691c\u7d22\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n<p>\n\u25a0AD \u5168\u691c\u7d22\n<\/p>\n<p>\n\u5358\u7d14\u306b\u3001AD \u306e\u60c5\u5831\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002\n<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nPrivate Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click\r\n\r\n\tDim root As New DirectoryEntry(&quot;LDAP:\/\/win2008-sv\/DC=moonmile,DC=local&quot;, &quot;masuda&quot;, &quot;password&quot;)\r\n\tDim se As New DirectorySearcher(root)\r\n\r\n\tListBox1.Items.Clear()\r\n\tFor Each res As SearchResult In se.FindAll\r\n\t\tDim de As DirectoryEntry = res.GetDirectoryEntry\r\n\t\tDebug.Print(de.Path)\r\n\t\tListBox1.Items.Add(de.Path)\r\n\tNext\r\nEnd Sub\r\n<\/pre>\n<p>\nLDAP \u30af\u30a8\u30ea\u3092\u6307\u5b9a\u3057\u3066\u3001DirectoryEntry \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u3001\u30c9\u30e1\u30a4\u30f3\u306b\u5165\u3063\u3066\u3044\u306a\u3044\u72b6\u614b\u306a\u306e\u3067\u3001AD \u3092\u691c\u7d22\u53ef\u80fd\u306a\u30e6\u30fc\u30b6\u30fc\u540d\u3068\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u65e2\u306b\u30c9\u30e1\u30a4\u30f3\u306b\u5165\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u3001\n<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nDim root As New DirectoryEntry(&quot;LDAP:\/\/win2008-sv\/DC=moonmile,DC=local&quot;)\r\n<\/pre>\n<p>\n\u306e\u3088\u3046\u306b\u6307\u5b9a\u3057\u3066\u3082 OK \u3067\u3059\u3002\u307e\u305f \u30c9\u30e1\u30a4\u30f3\u30b5\u30fc\u30d0\u30fc\u306e\u30d5\u30a9\u30ef\u30fc\u30c9\u304c\u304d\u3061\u3093\u3068\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308c\u3070\u3001\n<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nDim root As New DirectoryEntry(&quot;LDAP:\/\/DC=moonmile,DC=local&quot;)\r\n<\/pre>\n<p>\n\u306e\u3088\u3046\u306b\u3001\u30b5\u30fc\u30d0\u30fc\u540d\u304c\u7121\u304f\u3066\u3082\u52d5\u4f5c\u3057\u307e\u3059\u3002\n<\/p>\n<p>\n\u5168\u691c\u7d22\u3057\u3066\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u5185\u3067 for\/if \u3057\u3066\u3082\u826f\u3044\u306e\u3067\u3059\u304c\u3001\u30c9\u30e1\u30a4\u30f3\u30b5\u30fc\u30d0\u30fc\u306b\u8ca0\u62c5\u3092\u639b\u3051\u305d\u3046\u306a\u306e\u3067\u3001\u3082\u3046\u3061\u3087\u3063\u3068\u5de5\u592b\u304c\u5fc5\u8981\u3067\u3059\u3002\n<\/p>\n<p>\n\u25a0CN \u306a\u3069\u3067\u691c\u7d22\u3092\u7d5e\u308b\n<\/p>\n<p>\n\u5916\u90e8\u306b\u516c\u958b\u3057\u3066\u3044\u308b\u5834\u5408\u300cCN=ForeignSecurityPrincipals\u300d\u3092\u4ed8\u3051\u308c\u3070\u5c11\u3057\u306f\u8ca0\u62c5\u304c\u8efd\u304f\u306a\u308a\u307e\u3059\u3002\n<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nPrivate Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click\r\n\tDim root As New DirectoryEntry(&amp;quot;LDAP:\/\/win2008-sv\/CN=ForeignSecurityPrincipals,DC=moonmile,DC=local&amp;quot;, &amp;quot;masuda&amp;quot;, &amp;quot;password&amp;quot;)\r\n\tDim obj = root.NativeObject\r\n\tDim se As New DirectorySearcher(root)\r\n\tDim de2 As DirectoryEntry = Nothing\r\n\tListBox1.Items.Clear()\r\n\tFor Each res As SearchResult In se.FindAll\r\n\t\tDim de As DirectoryEntry = res.GetDirectoryEntry\r\n\t\tDebug.Print(de.Path)\r\n\t\tListBox1.Items.Add(de.Path + &amp;quot; &amp;quot; + de.Properties(&amp;quot;displayName&amp;quot;).Value)\r\n\t\tIf de.Path.IndexOf(&amp;quot;\u5897\u7530 \u30c8\u30cb\u30fc&amp;quot;) &gt;= 0 Then\r\n\t\t\tde2 = de\r\n\t\tEnd If\r\n\tNext\r\n\tFor Each nm In de2.Properties.PropertyNames\r\n\t\tDebug.Print(nm)\r\n\tNext\r\nEnd Sub\r\n<\/pre>\n<p>\n\u8868\u793a\u540d\u3092\u8abf\u3079\u308b\u3068\u304d\u306f\u3001de.Properties(&#8220;displayName&#8221;).Value \u306e\u3088\u3046\u306b\u3001Properties \u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u4f7f\u3048\u3070 OK \u3067\u3059\u3002\u305f\u3060\u3057\u3001\u76ee\u7684\u306e\u30e6\u30fc\u30b6\u30fc\u304c\u6307\u5b9a\u3067\u304d\u308b\u5834\u5408\u306f\u3001DirectorySearcher \u3067 new \u3059\u308b\u3068\u304d\u306b\u30d5\u30a3\u30eb\u30bf\u30fc\u3092\u6307\u5b9a\u3057\u305f\u307b\u3046\u304c\u826f\u3055\u305d\u3046\u3067\u3059\u3002\n<\/p>\n<p>\n\u3061\u306a\u307f\u306b\u3001\u3053\u3053\u3067\u30c7\u30d0\u30c3\u30b0\u51fa\u529b\u3055\u308c\u308b\u30d7\u30ed\u30d1\u30c6\u30a3\u306f\u3001\u4ee5\u4e0b\u306e\u3082\u306e\u3067\u3059\u3002\n<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nobjectClass\r\ncn\r\nsn\r\ngivenName\r\ndistinguishedName\r\ninstanceType\r\nwhenCreated\r\nwhenChanged\r\ndisplayName\r\nuSNCreated\r\nmemberOf\r\nuSNChanged20111221\r\nname\r\nobjectGUID\r\nuserAccountControl\r\nbadPwdCount\r\ncodePage\r\ncountryCode\r\nbadPasswordTime\r\nlastLogoff\r\nlastLogon\r\npwdLastSet\r\nprimaryGroupID\r\nobjectSid\r\naccountExpires\r\nlogonCount\r\nsAMAccountName\r\nsAMAccountType\r\nuserPrincipalName\r\nobjectCategory\r\ndSCorePropagationData\r\nmsDS-SupportedEncryptionTypes\r\nnTSecurityDescriptor\r\n<\/pre>\n<p>\n\u3053\u3053\u3067\u306f\u3001\u8868\u793a\u540d\uff08displayName\uff09\u3068SID\uff08objectSid\uff09\u3092\u4f7f\u3044\u307e\u3059\u3002\u3042\u3068\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u5c5e\u3057\u3066\u3044\u308b\u30b0\u30eb\u30fc\u30d7\u3092 memberOf \u3092\u4f7f\u3046\u3068\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002\n<\/p>\n<p>\n\u25a0\u30d5\u30a3\u30eb\u30bf\u30fc\u3092\u4f7f\u3063\u3066\u307f\u308b\n<\/p>\n<p>\nDirectorySearcher \u30af\u30e9\u30b9\u3067\u6307\u5b9a\u3059\u308b\u30d5\u30a3\u30eb\u30bf\u30fc\uff08LDAP\u30af\u30a8\u30ea\uff09\u3092\u4f7f\u3063\u3066\u3001\u30ab\u30c6\u30b4\u30ea\uff08objectCategory\uff09\u3068\u540d\u524d\u3067\u691c\u7d22\u30c7\u30fc\u30bf\u3092\u7d5e\u308c\u307e\u3059\u3002\n<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nPrivate Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click\r\n\tDim root As New DirectoryEntry(&quot;LDAP:\/\/ad-sv\/DC=plan,DC=local&quot;, &quot;tomoaki&quot;, &quot;password&quot;)\r\n\tDim obj = root.NativeObject\r\n\tDim filter As String = &quot;(&(objectCategory=User)(name=tomoaki))&quot;\r\n\tDim se As New DirectorySearcher(root, filter)\r\n\tDim de As DirectoryEntry = se.FindOne.GetDirectoryEntry\r\n\r\n\tListBox1.Items.Clear()\r\n\tFor Each nm In de.Properties.PropertyNames\r\n\t\tDebug.Print(nm)\r\n\t\tDim s As String = String.Format(&quot;{0}={1}&quot;, nm, de.Properties(nm).Value)\r\n\t\tListBox1.Items.Add(s)\r\n\tNext\r\n\r\n\tDim sid As String = SidToStringSid(\r\n\t CType(de.Properties(&quot;objectSid&quot;).Value, Byte()))\r\n\tDebug.Print(sid)\r\n\r\nEnd Sub\r\n\r\nDeclare Auto Function ConvertSidToStringSid Lib &quot;advapi32.dll&quot; (ByVal pSID() As Byte, _\r\n\tByRef ptrSid As IntPtr) As Boolean\r\nPrivate Function SidToStringSid(ByRef bytes As Byte()) As String\r\n\r\n\tDim psid As IntPtr = Nothing\r\n\tDim sid As String = &quot;&quot;\r\n\tConvertSidToStringSid(bytes, psid)\r\n\tsid = System.Runtime.InteropServices.Marshal.PtrToStringAuto(psid)\r\n\tReturn sid\r\n\r\nEnd Function\r\n<\/pre>\n<p>\n\u3042\u3068\u3001\u304a\u307e\u3051\u3067\u3059\u304c\u3001objectSid \u3067\u53d6\u5f97\u3059\u308b\u30c7\u30fc\u30bf\u306f byte \u578b\u306e\u914d\u5217\u306a\u306e\u3067\u3061\u3087\u3063\u3068\u6271\u3044\u3065\u3089\u3044\u306e\u3067\u3059\u3002\u300cS-&#8230;\u300d\u306e\u3088\u3046\u306a\u6587\u5b57\u5217\u3067\u4f7f\u3063\u3066\u3044\u304d\u305f\u3044\u306e\u3067\u3001\u5909\u63db\u95a2\u6570\u3092\u4f5c\u308a\u307e\u3059\u3002\n<\/p>\n<p>\n\u3061\u306a\u307f\u306b\u3001CType(de.Properties(&#8220;objectSid&#8221;).Value, Byte()) \u306e\u3068\u3053\u308d\u304c\u975e\u5e38\u306b\u9045\u3044\u306e\u3067\u3059\u3088\u306d&#8230;CType \u3092\u4f7f\u3063\u3066 Byte \u914d\u5217\u306b\u3059\u308b\u3068\u3053\u308d\u304c\u9045\u3044\u3089\u3057\u3044\u3002DirectCast \u3092\u4f7f\u3063\u3066\u307f\u305f\u306e\u3067\u3059\u304c\u3001\u30b9\u30d4\u30fc\u30c9\u306f\u3055\u307b\u3069\u5909\u308f\u3089\u306a\u3044\u306e\u3067\u3001\u5999\u306a\u3053\u3068\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u3053\u306e\u3042\u305f\u308a\u306f\u3001\u5f8c\u3067\u8abf\u3079\u308b&#8230;\u30cf\u30ba\u3002\n<\/p>\n<p>\n\u25a0\u5c5e\u3057\u3066\u3044\u308b\u30b0\u30eb\u30fc\u30d7\u306e\u691c\u7d22\n<\/p>\n<p>\n\u30c9\u30e1\u30a4\u30f3\u306b\u30ed\u30b0\u30aa\u30f3\u3057\u3066\u3044\u308b\u30e6\u30fc\u30b6\u30fc\u306e SID \u306f WindowsIdentity.GetCurrent.User \u3067\u53d6\u5f97\u3067\u304d\u308b\u306e\u3067\u3001\u6700\u521d\u306e\u300cad-sv \u3067 &#8220;tomoaki&#8221; \u3092\u691c\u7d22\u300d\u90e8\u5206\u306f\u4e0d\u8981\u306b\u306a\u308a\u307e\u3059\u3002\n<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nPrivate Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click\r\n\r\n\t' ad-sv \u3067 &quot;tomoaki&quot; \u3092\u691c\u7d22\r\n\tDim root As New DirectoryEntry(&quot;LDAP:\/\/ad-sv\/DC=plan,DC=local&quot;, &quot;tomoaki&quot;, &quot;password&quot;)\r\n\tDim filter As String = &quot;(&(objectCategory=User)(name=tomoaki))&quot;\r\n\tDim se As New DirectorySearcher(root, filter)\r\n\tDim de As DirectoryEntry = se.FindOne.GetDirectoryEntry\r\n\tDim bytes As Byte() = CType(de.Properties(&quot;objectSID&quot;).Value, Byte())\r\n\tDim sid As String = SidToStringSid(bytes)\r\n\r\n\t' win2008-sv \u3067 sid \u3067\u691c\u7d22\r\n\troot = New DirectoryEntry(&quot;LDAP:\/\/win2008-sv\/CN=ForeignSecurityPrincipals,DC=moonmile,DC=local&quot;, &quot;masuda&quot;, &quot;password&quot;)\r\n\tfilter = String.Format(&quot;(&(objectCategory=User)(displayName={0}))&quot;, sid)\r\n\tse = New DirectorySearcher(root, filter)\r\n\tde = se.FindOne.GetDirectoryEntry\r\n\tDim sid2 As String = SidToStringSid(CType(de.Properties(&quot;objectSID&quot;).Value, Byte()))\r\n\r\n\tListBox1.Items.Add(&quot;SID1:&quot; + sid)\r\n\tListBox1.Items.Add(&quot;SID2:&quot; + sid2)\r\n\r\n\t' \u5c5e\u3057\u3066\u3044\u308b\u30b0\u30eb\u30fc\u30d7\u3092\u53d6\u5f97\r\n\troot = New DirectoryEntry(&quot;LDAP:\/\/win2008-sv\/DC=moonmile,DC=local&quot;, &quot;masuda&quot;, &quot;password&quot;)\r\n\tDim groups As List(Of DirectoryEntry) = GetGroups(root, de)\r\n\tFor Each ent As DirectoryEntry In groups\r\n\t\tListBox1.Items.Add(ent.Properties(&quot;name&quot;).Value)\r\n\tNext\r\nEnd Sub\r\n\r\nPrivate Function GetGroups(root As DirectoryEntry, de As DirectoryEntry) As List(Of DirectoryEntry)\r\n\tDim lst As New List(Of DirectoryEntry)\r\n\r\n\tIf de.Properties(&quot;memberOf&quot;).Value IsNot Nothing Then\r\n\t\tIf de.Properties(&quot;memberOf&quot;).Value.GetType Is GetType(String) Then\r\n\t\t\tDim grp As String = de.Properties(&quot;memberOf&quot;).Value\r\n\t\t\tDim se As New DirectorySearcher(root, String.Format(&quot;(&(objectCategory=Group)(distinguishedName={0}))&quot;, grp))\r\n\t\t\tDim ent As DirectoryEntry = se.FindOne.GetDirectoryEntry\r\n\t\t\tlst.Add(ent)\r\n\t\t\tlst.AddRange(GetGroups(root, ent))\r\n\t\tElse\r\n\t\t\tDim groups As Object() = CType(de.Properties(&quot;memberOf&quot;).Value, Object())\r\n\t\t\tFor Each grp As String In groups\r\n\t\t\t\tDim se As New DirectorySearcher(root, String.Format(&quot;(&(objectCategory=Group)(distinguishedName={0}))&quot;, grp))\r\n\t\t\t\tDim ent As DirectoryEntry = se.FindOne.GetDirectoryEntry\r\n\t\t\t\tlst.Add(ent)\r\n\t\t\t\tlst.AddRange(GetGroups(root, ent))\r\n\t\t\tNext\r\n\t\tEnd If\r\n\tEnd If\r\n\r\n\tReturn lst\r\nEnd Function\r\n<\/pre>\n<p>\nLDAP \u30af\u30a8\u30ea\u3092\u4f7f\u3063\u3066\u3001\u8868\u793a\u540d\uff08displayName\uff09\u306e SID \u306e\u4e00\u81f4\u3092\u691c\u7d22\u3059\u308b\u308f\u3051\u3067\u3059\u3002\u305d\u306e\u6642\u306e DirectoryEntry \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u3001\u305d\u308c\u305e\u308c\u306e\u30b0\u30eb\u30fc\u30d7\u306b\u5c5e\u3057\u3066\u3044\u308b\u306e\u3067\u3001memberOf \u3092\u4f7f\u3063\u3066\u8abf\u3079\u3066\u3044\u304d\u307e\u3059\u3002\u53d6\u5f97\u3057\u305f DirectoryEntry \u306e SID \u3092\u8868\u793a\u3055\u305b\u3066\u3044\u307e\u3059\u304c\u3001\u5b9f\u306f\u3053\u308c\u3082\u4e0d\u8981\u3067\u3059\u3002\n<\/p>\n<p>\n\u5c5e\u3057\u3066\u3044\u308b\u30b0\u30eb\u30fc\u30d7\u306f\u3001\u518d\u5e30\u7684\u306b\u691c\u7d22\u3055\u305b\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u306f\u3001GRP001 \u304c GRP001PA \u306b\u5c5e\u3057\u3066\u3044\u308b\u5834\u5408\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u5c5e\u3057\u3066\u3044\u308b\u30b0\u30eb\u30fc\u30d7\u3068\u3057\u3066\u306f\u300cGRP001,GRP001PA\u300d\u306e\u3088\u3046\u306b\u3001\u4e21\u65b9\u3068\u3082\u53d6\u5f97\u3055\u305b\u305f\u3044\u305f\u3081\u3067\u3059\u3002memberOf \u30d7\u30ed\u30d1\u30c6\u30a3\u3067\u53d6\u5f97\u3059\u308b\u30c7\u30fc\u30bf\u306f\u3001\u3084\u3084\u3053\u3057\u3044\u3053\u3068\u306b\u3001String \u5358\u4f53\u3068 object \u914d\u5217\u306e 2 \u7a2e\u985e\u304c\u5b58\u5728\u3057\u307e\u3059\u3002\u5c5e\u3057\u3066\u3044\u308b\u30b0\u30eb\u30fc\u30d7\u304c\uff11\u3064\u306e\u5834\u5408\u306f String \u5358\u4f53\u3067\u30012 \u3064\u4ee5\u4e0a\u5c5e\u3057\u3066\u3044\u308b\u5834\u5408\u306f\u3001String \u914d\u5217\u304c\u8fd4\u3055\u308c\u308b\u3068\u3044\u3046&#8230;.\u5909\u306a\u4ed5\u69d8\u306e\u305f\u3081\u3001GetType \u3067\u30af\u30e9\u30b9\u3092\u6bd4\u8f03\u3055\u305b\u3066\u3044\u307e\u3059\u3002\n<\/p>\n<p>\n\u3053\u3053\u307e\u3067\u6765\u308b\u3068\u3001\u5c5e\u3057\u3066\u3044\u308b\u30b0\u30eb\u30fc\u30d7\u306e\u4e00\u89a7\u304c\u53d6\u5f97\u3067\u304d\u308b\u306e\u3067\u3001\u30b0\u30eb\u30fc\u30d7\u306e\u30a8\u30f3\u30c8\u30ea\u304b\u3089 name \u30d7\u30ed\u30d1\u30c6\u30a3\u306a\u3069\u3092\u4f7f\u3048\u3070\u3001\u3069\u306e\u30b0\u30eb\u30fc\u30d7\u306b\u5c5e\u3057\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u306f\u7c21\u5358\u306b\u8abf\u3079\u3089\u308c\u307e\u3059\u3002\n<\/p>\n<p><a href='http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/12\/wpid-dworkblogimage20111222_02org.jpg'><img border='0' src='http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/12\/wpid-dworkblogimage20111222_02thum.jpg'\/><\/a><\/p>\n<p>\n\u25a0\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u554f\u984c\n<\/p>\n<p>\n\u3053\u308c\u3092\u8a66\u3057\u306b\u5b9f\u884c\u3059\u308b\u3068\u7d50\u69cb\u5f85\u305f\u3055\u308c\u307e\u3059\u3002\u591a\u5206\u3001LDAP \u30af\u30a8\u30ea\u306e\u4f5c\u308a\u65b9\u304c\u307e\u305a\u3044\u3088\u3046\u306a\u6c17\u304c\u3059\u308b\u306e\u3067\u3059\u304c\u3001object \u914d\u5217\u304b\u3089 byte \u914d\u5217\u3078\u306e\u30ad\u30e3\u30b9\u30c8(ctype)\u3082\u7d50\u69cb\u91cd\u3044\u306e\u3067\u3059\u3002\n<\/p>\n<p>\n\u6700\u5f8c\u306e\u4f8b\u3060\u3068\u3001\n<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n\tse = New DirectorySearcher(root, filter) \u26051\r\n\tde = se.FindOne.GetDirectoryEntry\r\n\tDim sid2 As String = SidToStringSid(CType(de.Properties(&quot;objectSID&quot;).Value, Byte())) \u26052\r\n<\/pre>\n<p>\n\u306e\u3088\u3046\u306b\u3001\u26051 \u306e\u691c\u7d22\u3068\u3001\u26052 \u306e byte \u914d\u5217\u3078\u306e\u5909\u63db\u3067\u9045\u304f\u306a\u308a\u307e\u3059\u3002<br \/>\n\u3053\u3053\u3067\u306f\u3001SID \u3092\u8868\u793a\u3055\u305b\u3066\u3044\u308b\u3060\u3051\u306a\u306e\u3067\u3001\u3053\u3053\u306f\u524a\u3063\u3066\u3057\u307e\u3046\u3068\u65e9\u304f\u306a\u308a\u307e\u3059\u3002\n<\/p>\n<p>\nLDAP \u30af\u30a8\u30ea\u306e\u691c\u7d22\u90e8\u5206\u306f\u3001\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u4f7f\u3046\u3088\u3046\u306b\u3059\u308c\u3070\u65e9\u304f\u306a\u308b\u3093\u3067\u3059\u304b\u306d&#8230;\u554f\u5408\u305b\u306a\u306e\u3067\u591a\u5c11\u306f\u639b\u304b\u3063\u3066\u3082\u3088\u3044\u306e\u3067\u3057\u3087\u3046\u304c\u3001\u3082\u3046\u3061\u3087\u3063\u3068\u30ec\u30b9\u30dd\u30f3\u30b9\u304c\u826f\u3044\u307b\u3046\u304c\u3044\u3044\u306a\u3041\u3068\u3002\n<\/p>\n<p>&#8212; \u88dc\u8db3 2011\/12\/22<\/p>\n<p>byte \u914d\u5217\u306e\u3068\u3053\u308d\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5206\u89e3\u3059\u308b\u3068\u3001<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nDim obj As Object = de.Properties(&quot;objectSid&quot;).Value \u2605\u3053\u3053\u3067\u9045\u304f\u306a\u3063\u3066\u3044\u308b\r\nDim bytes As Byte() = CType(obj, Byte())\r\nDim sid As String = SidToStringSid(bytes)\r\n<\/pre>\n<p>\u3069\u3046\u3084\u3089\u3001Properties \u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u5024\u3092\u62fe\u3063\u3066\u304f\u308b\u3068\u3053\u308d\u304c\u91cd\u305f\u3044\u3088\u3046\u3067\u3059\u3002byte \u914d\u5217\u306f\u95a2\u4fc2\u306a\u3044\u3067\u3059\u306d\u3002<br \/>\n\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u6709\u52b9\u306b\u3059\u308b\u3068\u304b\u3067\u3001\u30b9\u30d4\u30fc\u30c9\u304c\u3042\u304c\u308b\uff1f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>.NET \u3067\u3001\u30c9\u30e1\u30a4\u30f3\u30b5\u30fc\u30d0\u30fc\u306b\u3042\u308b\u60c5\u5831\u3092\u691c\u7d22\u3059\u308b\u306b\u306f\u30013 \u3064\u306e\u30af\u30e9\u30b9\u3092\u99c6\u4f7f\u3057\u307e\u3059\u3002 DirectoryEntry \u30af\u30e9\u30b9\uff1a \u30a8\u30f3\u30c8\u30ea\u305d\u306e\u3082\u306e DirectorySearcher \u30af\u30e9\u30b9\uff1a LDAP \u30af\u30a8\u30ea\u3067\u691c\u7d22 Sea &hellip; <a href=\"http:\/\/www.moonmile.net\/blog\/archives\/2669\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,33],"tags":[],"class_list":["post-2669","post","type-post","status-publish","format-standard","hentry","category-dev","category-vb"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/2669","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/comments?post=2669"}],"version-history":[{"count":3,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/2669\/revisions"}],"predecessor-version":[{"id":2671,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/2669\/revisions\/2671"}],"wp:attachment":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media?parent=2669"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/categories?post=2669"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/tags?post=2669"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}