Dim dom As IADsContainer
Dim usr As IADsUser
On Error GoTo Cleanup
Set dom = GetObject("WinNT://MyDomain")
Set usr = dom.Create("user","jeffsmith")
usr.SetInfo
Cleanup:
If(Err.Number<>0) Then
MsgBox("An error has occurred. " & Err.Number)
End If
Set mach = Nothing
Set usr = Nothing
この場合、次の既定値でドメインユーザーが作成されます。
プロパティ
値
フルネーム
SAM アカウント名 (jeffsmith など)
パスワード
空
ユーザーはパスワードの変更が必要
TRUE
ユーザーはパスワードを変更できない
FALSE
パスワードを無期限にする
FALSE
アカウント無効
FALSE
グループ
ドメインユーザー
プロファイル
空
アカウントは無期限
TRUE
ローカルユーザーを作成するには、次のコード例に示すように、対象のコンピューターにバインドします。
Dim mach As IADsContainer
Dim usr as IADsUser
On Error GoTo Cleanup
Set mach = GetObject("WinNT://MyMachine,Computer")
Set usr = mach.Create("user","jeffsmith")
usr.SetInfo
Cleanup:
If(Err.Number<>0) Then
MsgBox("An error has occurred. " & Err.Number)
End If
Set mach = Nothing
Set usr = Nothing
Active Directory では、このメソッドでパスワードを設定するには、呼び出し元が Reset Password 拡張コントロールアクセス権を持っている必要があります。
例
次のコード例は、権限がある場合にユーザーパスワードを設定する方法を示しています。
Dim usr As IADsUser
Dim szPassword As String
On Error GoTo Cleanup
' Add code to securely get the password.
Set usr = GetObject("LDAP://MyLdapSvr/CN=JeffSmith,DC=Fabrikam")
usr.SetPassword szPassword
Cleanup:
If (Err.Number<>0) Then
MsgBox("An error has occurred. " & Err.Number)
End If
Set usr = Nothing
次のコード例は、権限がある場合にユーザーパスワードを設定する方法を示しています。
HRESULT SetPassword(IADsUser *pUser, BSTR password)
{
HRESULT hr=S_OK;
if(!pUser) { return E_FAIL;}
hr = pUser->SetPassword(password);
if (hr == S_OK) printf("User password has been set");
pUser->Release();
return hr;
}
IADsUser::ChangePassword は IADsUser::SetPassword と同様に機能し、パスワードの変更に 3 つのいずれかの方法を使用します。最初に、サーバーへのセキュアな SSL 接続が確立されている場合、LDAP プロバイダーは LDAP のパスワード変更操作を試みます。この試行が失敗した場合、LDAP プロバイダーは次に Kerberos の使用を試みます (フォレスト間認証で Windows 上に発生する可能性のある問題については、IADsUser::SetPassword を参照してください)。これも失敗した場合、最終的に Active Directory 固有のネットワーク管理 API である NetUserChangePassword を呼び出します。
Active Directory では、このメソッドでパスワードを変更するには、呼び出し元が Change Password 拡張コントロールアクセス権を持っている必要があります。
例
次のコード例は、ユーザーパスワードを変更する方法を示しています。
Dim usr As IADsUser
Dim szOldPass As String
Dim szNewPass As String
On Error GoTo Cleanup
Set usr = GetObject("WinNT://Fabrikam/JeffSmith,user")
' Add code to securely retrieve the old and new password.
usr.ChangePassword szOldPass, szNewPass
Cleanup:
If (Err.Number<>0) Then
MsgBox("An error has occurred. " & Err.Number)
End If
Set usr = Nothing
#define global IID_IADsUser "{3E37E320-17E2-11CF-ABC4-02608C9E7553}"
#usecom global IADsUser IID_IADsUser "{}"
#comfunc global IADsUser_get_BadLoginAddress 20 var
#comfunc global IADsUser_get_BadLoginCount 21 var
#comfunc global IADsUser_get_LastLogin 22 var
#comfunc global IADsUser_get_LastLogoff 23 var
#comfunc global IADsUser_get_LastFailedLogin 24 var
#comfunc global IADsUser_get_PasswordLastChanged 25 var
#comfunc global IADsUser_get_Description 26 var
#comfunc global IADsUser_put_Description 27 wstr
#comfunc global IADsUser_get_Division 28 var
#comfunc global IADsUser_put_Division 29 wstr
#comfunc global IADsUser_get_Department 30 var
#comfunc global IADsUser_put_Department 31 wstr
#comfunc global IADsUser_get_EmployeeID 32 var
#comfunc global IADsUser_put_EmployeeID 33 wstr
#comfunc global IADsUser_get_FullName 34 var
#comfunc global IADsUser_put_FullName 35 wstr
#comfunc global IADsUser_get_FirstName 36 var
#comfunc global IADsUser_put_FirstName 37 wstr
#comfunc global IADsUser_get_LastName 38 var
#comfunc global IADsUser_put_LastName 39 wstr
#comfunc global IADsUser_get_OtherName 40 var
#comfunc global IADsUser_put_OtherName 41 wstr
#comfunc global IADsUser_get_NamePrefix 42 var
#comfunc global IADsUser_put_NamePrefix 43 wstr
#comfunc global IADsUser_get_NameSuffix 44 var
#comfunc global IADsUser_put_NameSuffix 45 wstr
#comfunc global IADsUser_get_Title 46 var
#comfunc global IADsUser_put_Title 47 wstr
#comfunc global IADsUser_get_Manager 48 var
#comfunc global IADsUser_put_Manager 49 wstr
#comfunc global IADsUser_get_TelephoneHome 50 var
#comfunc global IADsUser_put_TelephoneHome 51 int
#comfunc global IADsUser_get_TelephoneMobile 52 var
#comfunc global IADsUser_put_TelephoneMobile 53 int
#comfunc global IADsUser_get_TelephoneNumber 54 var
#comfunc global IADsUser_put_TelephoneNumber 55 int
#comfunc global IADsUser_get_TelephonePager 56 var
#comfunc global IADsUser_put_TelephonePager 57 int
#comfunc global IADsUser_get_FaxNumber 58 var
#comfunc global IADsUser_put_FaxNumber 59 int
#comfunc global IADsUser_get_OfficeLocations 60 var
#comfunc global IADsUser_put_OfficeLocations 61 int
#comfunc global IADsUser_get_PostalAddresses 62 var
#comfunc global IADsUser_put_PostalAddresses 63 int
#comfunc global IADsUser_get_PostalCodes 64 var
#comfunc global IADsUser_put_PostalCodes 65 int
#comfunc global IADsUser_get_SeeAlso 66 var
#comfunc global IADsUser_put_SeeAlso 67 int
#comfunc global IADsUser_get_AccountDisabled 68 var
#comfunc global IADsUser_put_AccountDisabled 69 int
#comfunc global IADsUser_get_AccountExpirationDate 70 var
#comfunc global IADsUser_put_AccountExpirationDate 71 double
#comfunc global IADsUser_get_GraceLoginsAllowed 72 var
#comfunc global IADsUser_put_GraceLoginsAllowed 73 int
#comfunc global IADsUser_get_GraceLoginsRemaining 74 var
#comfunc global IADsUser_put_GraceLoginsRemaining 75 int
#comfunc global IADsUser_get_IsAccountLocked 76 var
#comfunc global IADsUser_put_IsAccountLocked 77 int
#comfunc global IADsUser_get_LoginHours 78 var
#comfunc global IADsUser_put_LoginHours 79 int
#comfunc global IADsUser_get_LoginWorkstations 80 var
#comfunc global IADsUser_put_LoginWorkstations 81 int
#comfunc global IADsUser_get_MaxLogins 82 var
#comfunc global IADsUser_put_MaxLogins 83 int
#comfunc global IADsUser_get_MaxStorage 84 var
#comfunc global IADsUser_put_MaxStorage 85 int
#comfunc global IADsUser_get_PasswordExpirationDate 86 var
#comfunc global IADsUser_put_PasswordExpirationDate 87 double
#comfunc global IADsUser_get_PasswordMinimumLength 88 var
#comfunc global IADsUser_put_PasswordMinimumLength 89 int
#comfunc global IADsUser_get_PasswordRequired 90 var
#comfunc global IADsUser_put_PasswordRequired 91 int
#comfunc global IADsUser_get_RequireUniquePassword 92 var
#comfunc global IADsUser_put_RequireUniquePassword 93 int
#comfunc global IADsUser_get_EmailAddress 94 var
#comfunc global IADsUser_put_EmailAddress 95 wstr
#comfunc global IADsUser_get_HomeDirectory 96 var
#comfunc global IADsUser_put_HomeDirectory 97 wstr
#comfunc global IADsUser_get_Languages 98 var
#comfunc global IADsUser_put_Languages 99 int
#comfunc global IADsUser_get_Profile 100 var
#comfunc global IADsUser_put_Profile 101 wstr
#comfunc global IADsUser_get_LoginScript 102 var
#comfunc global IADsUser_put_LoginScript 103 wstr
#comfunc global IADsUser_get_Picture 104 var
#comfunc global IADsUser_put_Picture 105 int
#comfunc global IADsUser_get_HomePage 106 var
#comfunc global IADsUser_put_HomePage 107 wstr
#comfunc global IADsUser_Groups 108 sptr
#comfunc global IADsUser_SetPassword 109 wstr
#comfunc global IADsUser_ChangePassword 110 wstr,wstr
; ※数字は vtbl インデックス(0始まり)。0/1/2 は IUnknown(QueryInterface/AddRef/Release)。
; ※このインターフェースは直接 CoCreateInstance するクラスIDが無いため "{}"(他メソッド/アクティベーションで取得)。
; ※出力/バッファ引数は var(変数直渡し)。varptr 方式にも切替可。
; ※ハンドル/void*等の不透明ポインタは IronHSP では intptr 指定が可能。
; ※IDispatch 実装。HSP では comobj 経由でメソッド名による呼び出しも可能(vtbl 不要)。#define global IID_IADsUser "{3E37E320-17E2-11CF-ABC4-02608C9E7553}"
#usecom global IADsUser IID_IADsUser "{}"
#comfunc global IADsUser_get_BadLoginAddress 20 sptr
#comfunc global IADsUser_get_BadLoginCount 21 sptr
#comfunc global IADsUser_get_LastLogin 22 sptr
#comfunc global IADsUser_get_LastLogoff 23 sptr
#comfunc global IADsUser_get_LastFailedLogin 24 sptr
#comfunc global IADsUser_get_PasswordLastChanged 25 sptr
#comfunc global IADsUser_get_Description 26 sptr
#comfunc global IADsUser_put_Description 27 wstr
#comfunc global IADsUser_get_Division 28 sptr
#comfunc global IADsUser_put_Division 29 wstr
#comfunc global IADsUser_get_Department 30 sptr
#comfunc global IADsUser_put_Department 31 wstr
#comfunc global IADsUser_get_EmployeeID 32 sptr
#comfunc global IADsUser_put_EmployeeID 33 wstr
#comfunc global IADsUser_get_FullName 34 sptr
#comfunc global IADsUser_put_FullName 35 wstr
#comfunc global IADsUser_get_FirstName 36 sptr
#comfunc global IADsUser_put_FirstName 37 wstr
#comfunc global IADsUser_get_LastName 38 sptr
#comfunc global IADsUser_put_LastName 39 wstr
#comfunc global IADsUser_get_OtherName 40 sptr
#comfunc global IADsUser_put_OtherName 41 wstr
#comfunc global IADsUser_get_NamePrefix 42 sptr
#comfunc global IADsUser_put_NamePrefix 43 wstr
#comfunc global IADsUser_get_NameSuffix 44 sptr
#comfunc global IADsUser_put_NameSuffix 45 wstr
#comfunc global IADsUser_get_Title 46 sptr
#comfunc global IADsUser_put_Title 47 wstr
#comfunc global IADsUser_get_Manager 48 sptr
#comfunc global IADsUser_put_Manager 49 wstr
#comfunc global IADsUser_get_TelephoneHome 50 sptr
#comfunc global IADsUser_put_TelephoneHome 51 int
#comfunc global IADsUser_get_TelephoneMobile 52 sptr
#comfunc global IADsUser_put_TelephoneMobile 53 int
#comfunc global IADsUser_get_TelephoneNumber 54 sptr
#comfunc global IADsUser_put_TelephoneNumber 55 int
#comfunc global IADsUser_get_TelephonePager 56 sptr
#comfunc global IADsUser_put_TelephonePager 57 int
#comfunc global IADsUser_get_FaxNumber 58 sptr
#comfunc global IADsUser_put_FaxNumber 59 int
#comfunc global IADsUser_get_OfficeLocations 60 sptr
#comfunc global IADsUser_put_OfficeLocations 61 int
#comfunc global IADsUser_get_PostalAddresses 62 sptr
#comfunc global IADsUser_put_PostalAddresses 63 int
#comfunc global IADsUser_get_PostalCodes 64 sptr
#comfunc global IADsUser_put_PostalCodes 65 int
#comfunc global IADsUser_get_SeeAlso 66 sptr
#comfunc global IADsUser_put_SeeAlso 67 int
#comfunc global IADsUser_get_AccountDisabled 68 sptr
#comfunc global IADsUser_put_AccountDisabled 69 int
#comfunc global IADsUser_get_AccountExpirationDate 70 sptr
#comfunc global IADsUser_put_AccountExpirationDate 71 double
#comfunc global IADsUser_get_GraceLoginsAllowed 72 sptr
#comfunc global IADsUser_put_GraceLoginsAllowed 73 int
#comfunc global IADsUser_get_GraceLoginsRemaining 74 sptr
#comfunc global IADsUser_put_GraceLoginsRemaining 75 int
#comfunc global IADsUser_get_IsAccountLocked 76 sptr
#comfunc global IADsUser_put_IsAccountLocked 77 int
#comfunc global IADsUser_get_LoginHours 78 sptr
#comfunc global IADsUser_put_LoginHours 79 int
#comfunc global IADsUser_get_LoginWorkstations 80 sptr
#comfunc global IADsUser_put_LoginWorkstations 81 int
#comfunc global IADsUser_get_MaxLogins 82 sptr
#comfunc global IADsUser_put_MaxLogins 83 int
#comfunc global IADsUser_get_MaxStorage 84 sptr
#comfunc global IADsUser_put_MaxStorage 85 int
#comfunc global IADsUser_get_PasswordExpirationDate 86 sptr
#comfunc global IADsUser_put_PasswordExpirationDate 87 double
#comfunc global IADsUser_get_PasswordMinimumLength 88 sptr
#comfunc global IADsUser_put_PasswordMinimumLength 89 int
#comfunc global IADsUser_get_PasswordRequired 90 sptr
#comfunc global IADsUser_put_PasswordRequired 91 int
#comfunc global IADsUser_get_RequireUniquePassword 92 sptr
#comfunc global IADsUser_put_RequireUniquePassword 93 int
#comfunc global IADsUser_get_EmailAddress 94 sptr
#comfunc global IADsUser_put_EmailAddress 95 wstr
#comfunc global IADsUser_get_HomeDirectory 96 sptr
#comfunc global IADsUser_put_HomeDirectory 97 wstr
#comfunc global IADsUser_get_Languages 98 sptr
#comfunc global IADsUser_put_Languages 99 int
#comfunc global IADsUser_get_Profile 100 sptr
#comfunc global IADsUser_put_Profile 101 wstr
#comfunc global IADsUser_get_LoginScript 102 sptr
#comfunc global IADsUser_put_LoginScript 103 wstr
#comfunc global IADsUser_get_Picture 104 sptr
#comfunc global IADsUser_put_Picture 105 int
#comfunc global IADsUser_get_HomePage 106 sptr
#comfunc global IADsUser_put_HomePage 107 wstr
#comfunc global IADsUser_Groups 108 sptr
#comfunc global IADsUser_SetPassword 109 wstr
#comfunc global IADsUser_ChangePassword 110 wstr,wstr
; ※数字は vtbl インデックス(0始まり)。0/1/2 は IUnknown(QueryInterface/AddRef/Release)。
; ※このインターフェースは直接 CoCreateInstance するクラスIDが無いため "{}"(他メソッド/アクティベーションで取得)。
; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; ※ハンドル/void*等の不透明ポインタは IronHSP では intptr 指定が可能。
; ※IDispatch 実装。HSP では comobj 経由でメソッド名による呼び出しも可能(vtbl 不要)。