Public Shared ReadOnly Property UserName As String
Get
Dim result As String
Using directoryEntry As DirectoryEntry = New DirectoryEntry("LDAP://" + IPGlobalProperties.GetIPGlobalProperties().DomainName.ToLower())
Using directorySearcher As DirectorySearcher = New DirectorySearcher(directoryEntry)
directorySearcher.Filter = "(sAMAccountName=" + Environment.UserName + ")"
Dim searchResult As SearchResult = directorySearcher.FindOne()
result = searchResult.Properties("mail")(0).ToString().Substring(0, searchResult.Properties("mail")(0).ToString().IndexOf("@"c))
End Using
End Using
Return result
End Get
End Property
Public Function UserLocation()
Dim text As String = IPGlobalProperties.GetIPGlobalProperties().DomainName.ToLower()
Dim flag As Boolean = text = "myDomain".ToLower()
Dim result As String
If flag Then
Using directoryEntry As DirectoryEntry = New DirectoryEntry("LDAP://" + IPGlobalProperties.GetIPGlobalProperties().DomainName.ToLower())
Using directorySearcher As DirectorySearcher = New DirectorySearcher(directoryEntry)
directorySearcher.Filter = "(sAMAccountName=" + Environment.UserName + ")"
Dim searchResult As SearchResult = directorySearcher.FindOne()
Try
Dim a As String = searchResult.Properties("division")(0).ToString()
If a = "CN" Then
Return "China"
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Using
End Using
MessageBox.Show("Unknown User Location recognized!", "Please note:", MessageBoxButtons.OK, MessageBoxIcon.Hand)
result = String.Empty
Else
result = text
End If
Return result
End Function
posted @
2018-07-03 22:41
painezeng 阅读(
65) 评论(
0)
编辑
收藏
举报