我正在编写一个 VBScript 文件来获取当前登录的用户名和电子邮件地址。一些解决方案需要硬编码用户名/密码来执行 LDAP 搜索,而另一些则不需要。
每种方法的优缺点是什么?
选项 1:没有 LDAP 用户名/密码 源
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName) ' Currently logged in User
Response.Write("Email: " & objUser.mail)
选项 2:硬编码 LDAP 用户名/密码 源
strUsername = split(Request.ServerVariables("LOGON_USER"),"\")(1)
Set rootDSE = GetObject("LDAP://RootDSE")
Set oConn = CreateObject("ADODB.Connection")
sDomainContainer = rootDSE.Get("defaultNamingContext")
oConn.Provider = "ADSDSOObject"
oConn.properties("user id") = sLdapReaderUsername
oConn.properties("password") = sLdapReaderPassword
oConn.Open "ADs Provider"
sQuery = "<LDAP://" & sDomainContainer & ">;(sAMAccountName=" & strUsername & ");adspath,mail,displayName,sAMAccountName;subtree"
Set userRS = oConn.Execute(sQuery)
If NOT userRS.EOF AND NOT err Then Response.Write(userRS("mail"))