您的位置:首页 > 编程语言 > VB

VBS获取当前登录的用户全名和邮件地址

2013-08-12 11:23 561 查看
Function GetEmail(strAccountName, strDomainName)
Dim adoLDAPCon, _
adoLDAPRS, _
strLDAP

Set adoLDAPCon = CreateObject("ADODB.Connection")
adoLDAPCon.Provider = "ADsDSOObject"
adoLDAPCon.Open "ADSI"
strLDAP = "'LDAP://" & strDomainName & "'"
Set adoLDAPRS = adoLDAPCon.Execute("select mail from " & strLDAP & " WHERE objectClass = 'user'"& " And samAccountName = '" & strAccountName & "'")
With adoLDAPRS
If Not .EOF Then
GetEmail = .Fields("mail")
Else
GetEmail = ""
End If
End With
adoLDAPRS.Close
Set adoLDAPRS = Nothing
Set adoLDAPCon = Nothing
End Function

Set objNetwork = CreateObject("Wscript.Network")
strUser = objNetwork.UserName
strDomain = objNetwork.UserDomain
mailAdr = GetEmail(strUser, strDomain)
print  mailAdr

sADSPath= strDomain & "/" & strUser
Set oUser = GetObject("WinNT://" & sADSPath & ",user")
print oUser.FullName
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: