Board logo

标题: [转贴] VBS使用LDAP验证域用户账号 [打印本页]

作者: yu2n    时间: 2013-8-1 21:44     标题: VBS使用LDAP验证域用户账号

VBS使用LDAP验证域用户账号
功能:验证域用户账号
环境:WinXP域内主机、WinXP域外主机、Win2003
作者:yu2n
引用: http://www.oocities.org/calinradoni/vbLDAPAuth.html
  1. If WScript.Arguments.Count = 3 Then
  2.     Msgbox LDAP_Authenticate(WScript.Arguments.item(0), WScript.Arguments.item(1), WScript.Arguments.item(2))
  3. Else
  4.     sTip = "验证域用户账号:" & vbCrLf
  5.     sTip = sTip & "  LDAP_Authenticate.VBS  <LDAPServer> <User> <Password>" & vbCrLf & vbCrLf
  6.     sTip = sTip & "    LDAPServer:域DC服务器如 dc1.demo.com" & vbCrLf
  7.     sTip = sTip & "    User:域用户名" & vbCrLf
  8.     sTip = sTip & "    Password:域用户密码" & vbCrLf
  9.     Msgbox sTip
  10. End If
  11. ' LDAP Authentication to Active Directory in VBScript
  12. ' http://www.oocities.org/calinradoni/vbLDAPAuth.html
  13. ' LDAP_Authenticate texdgdc01.texwinca.com texwinca\af071 Ct123456
  14. Function LDAP_Authenticate(ByVal sLDAPServer, ByVal sADUserName, ByVal sADPassword)
  15.     Const ADS_SECURE_AUTHENTICATION = &h0001
  16.     Const ADS_SERVER_BIND = &h0200
  17.     Dim sRoot, dso, xResult
  18.     sRoot = "LDAP://" & sLDAPServer
  19.     Set dso = GetObject("LDAP:")
  20.     On Error Resume Next
  21.     Set xResult = dso.OpenDSObject(sRoot, sADUserName, sADPassword, ADS_SECURE_AUTHENTICATION Or ADS_SERVER_BIND)
  22.     If Err.number = 0 Then
  23.         LDAP_Authenticate = True
  24.     Else
  25.         LDAP_Authenticate = False
  26.     End If
  27. End Function
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2