【发布时间】:2014-11-19 11:28:48
【问题描述】:
我正在使用下面的代码来获取 logge don 用户的登录名。这在连接到网络/域时工作正常。但是当离线时,我在第 3 行得到一个错误:
PrincipalServerDownException 未处理
无法联系到服务器。
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim currentADUser As System.DirectoryServices.AccountManagement.UserPrincipal
currentADUser = System.DirectoryServices.AccountManagement.UserPrincipal.Current
Dim DisplayName As String = currentADUser.GivenName & " " & currentADUser.Surname
Label5.Text = DisplayName
Label4.Text = GetUserProperties()
End Sub
我怎样才能检查它,并向用户返回一个有用的错误,例如“不在网络上”或“未连接到域”,然后退出?我已经尝试了以下方法,但这只是给出了同样的错误:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim currentADUser As System.DirectoryServices.AccountManagement.UserPrincipal
If System.DirectoryServices.AccountManagement.UserPrincipal.Current Is Nothing Then
MsgBox("Network Error: No Connection to Domain")
Application.Exit()
Else ....
End if
End Sub
【问题讨论】:
标签: vb.net active-directory directoryservices