【问题标题】:Returning References from Function in VBScript从 VBScript 中的函数返回引用
【发布时间】:2011-02-05 18:23:06
【问题描述】:

我在 VBScript 上脱发了。如何将引用作为函数的返回值传递?

目前我的代码如下所示:

Set objUser = FindUser("bendert")

REM Searches Directory for the User
Function FindUser(UserLoginName)
    Wscript.Echo "Querying AD to retrieve user-data" 

 Set objConnection = CreateObject("ADODB.Connection")
 objConnection.Open "Provider=ADsDSOObject;"

 Set objCommand = CreateObject("ADODB.Command")
 objCommand.ActiveConnection = objConnection

 'Get user Using LDAP/ADO.  There is an easier way
 'to bind to a user object using the WinNT provider,
 'but this way is a better for educational purposes
 Set oRoot = GetObject("LDAP://rootDSE")
 'work in the default domain
 sDomain = oRoot.Get("defaultNamingContext")
 Set oDomain = GetObject("LDAP://" & sDomain)
 sBase = "<" & oDomain.ADsPath & ">"
 'Only get data for login name requested
 sFilter = "(&(sAMAccountName="& UserLoginName &")(objectClass=user))"
 sAttribs = "adsPath"
 sDepth = "subTree"

 sQuery = sBase & ";" & sFilter & ";" & sAttribs & ";" & sDepth
 WScript.Echo "LDAP Query is:" & sQuery &""

 objCommand.CommandText=sQuery
 Set objRecordSet = objCommand.Execute

 FindUser = GetObject(objRecordSet.Fields("adspath"))
 WScript.Echo "You E-Mail Address is: " & objUser.EmailAddress
 objConnection.Close    
End Function

不幸的是,VBScript 在我对函数的返回值进行赋值的那一行抛出了一个错误。

FindUser = GetObject(objRecordSet.Fields("adspath"))

错误看起来像“错误数量的参数或无效的属性分配”。

我做错了什么?

【问题讨论】:

    标签: windows scripting vbscript


    【解决方案1】:

    看起来你需要:

    Set FindUser = GetObject(objRecordSet.Fields("adspath"))
    

    【讨论】:

      【解决方案2】:
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-29
      • 1970-01-01
      • 1970-01-01
      • 2016-08-17
      • 1970-01-01
      • 1970-01-01
      • 2022-11-24
      相关资源
      最近更新 更多