Try
Dim context As New System.DirectoryServices.AccountManagement.PrincipalContext(System.DirectoryServices.AccountManagement.ContextType.Domain)
Dim user As System.DirectoryServices.AccountManagement.UserPrincipal = System.DirectoryServices.AccountManagement.UserPrincipal.Current
If user IsNot Nothing Then
Dim isAuthenticated As Boolean = context.ValidateCredentials(user.SamAccountName, "用户密码")
If isAuthenticated Then
msgbox("用户通过AD认证。")
Else
msgbox("用户没有通过AD认证。")
End If
Else
msgbox("无法获取当前用户。")
End If
Catch ex As Exception
msgbox("发生错误: " & ex.Message)
End Try
[此贴子已经被作者于2024/11/1 10:23:00编辑过]