2010-04-08 4 views
1

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.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 

Unfortunatley VBScript를 내가 함수의 반환 값에 할당을 라인에 오류가 발생합니다.

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

"잘못된 인수 개수 또는 잘못된 속성 할당"과 같은 오류가 발생합니다.

내가 뭘 잘못하고 있니?

답변

3

는 당신이 필요로하는 것 같은데 :

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