Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 从VBScript中的函数返回引用_Windows_Scripting_Vbscript - Fatal编程技术网

Windows 从VBScript中的函数返回引用

Windows 从VBScript中的函数返回引用,windows,scripting,vbscript,Windows,Scripting,Vbscript,我在用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.Conne

我在用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
该错误看起来像参数数目错误或属性分配无效

我做错了什么?

设置FindUser=

设置FindUser=

看起来您需要:

Set FindUser = GetObject(objRecordSet.Fields("adspath"))
看起来您需要:

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