none
VBscript: There is no such object on the server

    Question

  • I've got an HTA that should take a few user choices and spit out a text file with either all SMTP addresses, or just the primary address for users in a given OU or e-mail domain. The source is below.

    I took a working script and added the choices. When I enter the required fields and click submit, I get an error for line 71, stating that there is no such object on the server. The line referenced in the error is part of the original, functional script so I'm confused. 

    Can anyone see what's wrong? Thanks.

    <html>
    	<!--Version 1.0.0
    
    	-->
    	<head>
    		<title>Get SMTP Addresses</title>
    		<HTA:APPLICATION ICON=simple.ico sysMenu=yes>
    		<script language="VBScript">
    			Sub Window_onLoad
    				window.resizeTo 500,400
    			End Sub
    			Sub RunScript
    				Location.Reload(True)
    			End Sub
    			Sub Main()
    				Const ForWriting = 2
    				
    				'setup variables
    				strAddressType = addressType.value
    				strObjectType = objectType.value
    				strScope = scope.value
    				strScopeText = scopeText.value
    				If strScopeText = "" Then
    					If strScope = "ou" Then 
    						Msgbox "You forgot to enter an OU. I'm going to exit out now so you can try again."
    						Exit Sub
    					Else
    						Msgbox "You forgot to enter an e-mail domain. I'm going to exit out now so you can try again."
    						Exit Sub
    					End if
    				End If
    				strFileName = fileName.value
    				If strScopeText = "" Then
    					Msgbox "You forgot to enter an output file name. I'm going to exit out now so you can try again."
    					Exit Sub
    				End if
    				
    				'Path for the output file
    				Set WshShell = CreateObject("WScript.Shell")
    				Set WshSysEnv = WshShell.Environment("PROCESS")
    				strProfilePath = WshSysEnv("Userprofile")
    				filePath = strProfilePath & "\" & strFileName
    
    				'Setup output file
    				Set objFSO = CreateObject("Scripting.FileSystemObject")
    				Set objTextFile = objFSO.OpenTextFile(filepath, ForWriting, True)
    
    				'Create Objects for LDAP Queries
    				Set rootDSE = GetObject("LDAP://RootDSE")
    				DomainContainer = rootDSE.Get("defaultNamingContext")
    
    				Set conn = CreateObject("ADODB.Connection")
    				conn.Provider = "ADSDSOObject"
    				conn.Open "ADs Provider"
    				
    				'LDAP query string
    				Select Case LCase(strScope)
    					Case "ou"
    						strLDAP = "<LDAP://" & strScopeText & ",ou=customers," & DomainContainer & ">;(&(mailnickname=*)(objectCategory=person)(objectClass=" & strObjectType & "));adspath;subtree"
    					Case "emaildomain"
    						strLDAP = "<LDAP://" & DomainContainer & ">;(&(mailnickname=*)(objectCategory=person)(objectClass=" & strObjectType & ")(proxyAddresses=*@" & strScopeText & "));adspath;subtree"
    				End Select
    			
    				'Get query results and output to file
    				Set oComm = CreateObject("ADODB.Command")
    				oComm.ActiveConnection = conn
    				oComm.CommandText = strLDAP
    				oComm.Properties("Sort on") = "DisplayName"
    				oComm.Properties("Page size") = 1500
    
    				Set rs = oComm.Execute
    
    				While Not rs.EOF
    					Set FoundObject = GetObject (rs.Fields(0).Value)
    					arrProxyAddresses = FoundObject.proxyAddresses
    					For Each Address In arrProxyAddresses
    						If left(Address,5) = strAddressType Then
    						 objTextFile.writeLine(FoundObject.Displayname & vbTab & Address)
    						End if
    					Next
    					rs.MoveNext
    				Wend
    
    				MsgBox "Processing complete!"
    			End Sub
    		</script>
    	</head>
    	<body>
    		Do you want to search for primary SMTP addresses, or all?
    		<br />
    		<select size="1" name="addressType">
    			<option value="primary">Primary</option>
    			<option value="all">All</option>
    		</select>
    		<br />
    		<br />
    		Do you want to search for people or main contacts?
    		<br />
    		<select size="1" name="objectType">
    			<option value="user">People</option>
    			<option value="contact">Mail Contact</option>
    		</select>
    		<br />
    		<br />
    		Do you want to search by e-mail domain or OU?
    		<br />
    		<select size="1" name="scope">
    			<option value="ou">OU</option>
    			<option value="emailDomain">E-mail domain</option>
    		</select>
    		<br />
    		<br />
    		Enter the e-mail domain, or OU (e.g. critigen.com or ou=CompanyOU)
    		<br />
    		<input type="text" name="scopeText" />
    		<br />
    		<br />
    		Enter a name for the output text file (e.g. customerSMTPAddresses.txt) 
    		<br />
    		<input type="text" name="fileName" />
    		<br />
    		<input type="submit" value="Submit" OnClick="Main()" />
    	</body>
    </html>


    • Edited by WinadminSM Tuesday, September 04, 2012 7:03 PM
    Tuesday, September 04, 2012 7:02 PM

Answers

  • I also cannot tell which is line 71, and after a quick glance I don't see any objects that are not bound or are missing. Possibly, the base of the query is invalid. However, you use ADO to retrieve users that meet some conditions, then you bind to each user object to retrieve attribute values. Why not add the attributes (displayName and proxyAddresses) to the comma delimited list of attribute values to be retrieved (instead of ADsPath) and retrieve the values directly from the recordset (to avoid binding to every user object)?

    What is strScopeText? Is this similar to "ou=West" or some other domain component/container/ou? And of course the value of DomainContainer must be a valid DN.


    Richard Mueller - MVP Directory Services

    Tuesday, September 04, 2012 8:06 PM
    Moderator

All replies

  • Which line is line 71?

    Bill

    Tuesday, September 04, 2012 7:32 PM
    Moderator
  • I also cannot tell which is line 71, and after a quick glance I don't see any objects that are not bound or are missing. Possibly, the base of the query is invalid. However, you use ADO to retrieve users that meet some conditions, then you bind to each user object to retrieve attribute values. Why not add the attributes (displayName and proxyAddresses) to the comma delimited list of attribute values to be retrieved (instead of ADsPath) and retrieve the values directly from the recordset (to avoid binding to every user object)?

    What is strScopeText? Is this similar to "ou=West" or some other domain component/container/ou? And of course the value of DomainContainer must be a valid DN.


    Richard Mueller - MVP Directory Services

    Tuesday, September 04, 2012 8:06 PM
    Moderator
  • The LDAP query is invalid.  Print it out with a msgbox to see what it is.

    Even if you fix that the script will return nothing doue to logic errors.

    The following line will never match anything:
    If left(Address,5) = strAddressType Then


    ¯\_(ツ)_/¯

    Tuesday, September 04, 2012 9:02 PM
  • Hi,

    You seem to have abandoned this question. If you still need help, please start a new question.

    Bill

    Wednesday, September 12, 2012 5:48 PM
    Moderator