Groups および Users Append、ChangePassword メソッドの例 (VB)
この例では、新しい Group と新しい User をシステムに追加して、Groups の Append メソッドと Users の Append メソッドを示します。 新しい Group は、新しい User の Groups コレクションに追加されます。 その結果、新しい User が Group に追加されます。 また、ChangePassword メソッドを使用して User パスワードを指定します。
注意
Windows 認証をサポートするデータ ソース プロバイダーに接続している場合、接続文字列のユーザー ID とパスワード情報ではなく、Trusted_Connection=yes または Integrated Security = SSPI を指定してください。
' BeginGroupVB
Sub Main()
On Error GoTo GroupXError
Dim cat As ADOX.Catalog
Dim usrNew As ADOX.User
Dim usrLoop As ADOX.User
Dim grpLoop As ADOX.Group
Set cat = New ADOX.Catalog
cat.ActiveConnection = "Provider='Microsoft.Jet.OLEDB.4.0';" & _
"Data Source='Northwind.mdb';" & _
"jet oledb:system database=" & _
"'system.mdw'"
With cat
'Create and append new group with a string.
.Groups.Append "Accounting"
' Create and append new user with an object.
Set usrNew = New ADOX.User
usrNew.Name = "Pat Smith"
usrNew.ChangePassword "", "Password1"
.Users.Append usrNew
' Make the user Pat Smith a member of the
' Accounting group by creating and adding the
' appropriate Group object to the user's Groups
' collection. The same is accomplished if a User
' object representing Pat Smith is created and
' appended to the Accounting group Users collection
usrNew.Groups.Append "Accounting"
' Enumerate all User objects in the
' catalog's Users collection.
For Each usrLoop In .Users
Debug.Print " " & usrLoop.Name
Debug.Print " Belongs to these groups:"
' Enumerate all Group objects in each User
' object's Groups collection.
If usrLoop.Groups.Count <> 0 Then
For Each grpLoop In usrLoop.Groups
Debug.Print " " & grpLoop.Name
Next grpLoop
Else
Debug.Print " [None]"
End If
Next usrLoop
' Enumerate all Group objects in the default
' workspace's Groups collection.
For Each grpLoop In .Groups
Debug.Print " " & grpLoop.Name
Debug.Print " Has as its members:"
' Enumerate all User objects in each Group
' object's Users collection.
If grpLoop.Users.Count <> 0 Then
For Each usrLoop In grpLoop.Users
Debug.Print " " & usrLoop.Name
Next usrLoop
Else
Debug.Print " [None]"
End If
Next grpLoop
' Delete new User and Group objects because this
' is only a demonstration.
' These two line are commented out because the sub "OwnersX" uses
' the group "Accounting".
' .Users.Delete "Pat Smith"
' .Groups.Delete "Accounting"
End With
'Clean up
Set cat.ActiveConnection = Nothing
Set cat = Nothing
Set usrNew = Nothing
Exit Sub
GroupXError:
Set cat = Nothing
Set usrNew = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
' EndGroupVB
参照
Append メソッド (ADOX Groups)
Append メソッド (ADOX Users)
Catalog オブジェクト (ADOX)
ChangePassword メソッド (ADOX)
Group オブジェクト (ADOX)
Groups コレクション (ADOX)
User オブジェクト (ADOX)
Users コレクション (ADOX)