gpt4 book ai didi

windows - 从 VBScript 中的函数返回引用

转载 作者:可可西里 更新时间:2023-11-01 11:22:32 25 4
gpt4 key购买 nike

我在 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"))

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

我做错了什么?

最佳答案

看起来你需要:

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

关于windows - 从 VBScript 中的函数返回引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2601133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com