Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

syntax help 1

Status
Not open for further replies.

JimmyZ1

Technical User
Mar 31, 2004
397
Can someone help me with the syntax... something is wrong with the imputbox


Input1 = InputBox("Enter your OU for example XXX:")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("compt.txt", ForAppending, True)

Set Name1 = "LDAP://OU=Computers," & "OU=" & Input1 & ",DC=com
 
This will confuse yourself less.
[tt]
sadsipath="LDAP://OU=Computers," & "OU=" & Input1 & ",DC=com"
set Name1=getobject(sadsipath)
[/tt]
This assumes also input1 is validated and does not contain special characters which need to be escaped.
 
Here is the whole thing

Const ForAppending = 8
Const F_RDON = 1
On Error Resume Next

Input1 = InputBox("Enter your OU for example XXX:")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("compt.txt", ForAppending, True)

sadsipath="="LDAP://OU=Computers," & "OU=" & Input1 & ",DC=com"
set Name1=getobject(sadsipath)

Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name, Location from 'Name1' " _
& "where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
' Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
objTextFile.WriteLine(objRecordset.fields("Name").Value)
objRecordSet.MoveNext
Loop



It keeps hanging up and pegging out the processor
 
First, you practically must make at least a simple validation of input1 if user cancels or enter nothing as the input. Second, as a shortcut if you spare the above as it would catch invalid input or empty input, you have to catch the error for getting the reference of the ou object.
[tt]
'above same or modified
on error resume next
set Name1=getobject(sadsipath)
if err.number<>0 then
wscript.echo "Invalid ou or network error." & vbcrlf & _
hex(err.number) & vbcrlf & err.description & vbcrlf & _
"Operation aborted."
wscript.quit (err.number)
end if
on error goto 0
'continue...
[/tt]
or similarly scripted block.

The rest I did not look into.

- tsuji
 
There is a problem with this line interpreting the Name1

"Select Name, Location from 'Name1' " _
& "where objectClass='computer'"

I can put in the actual sadsipath and it works fine... I try to use anything other than that and it dumps
 
Well you do not query from the ou object like that.
[tt]
objCommand.CommandText = _
"Select Name, Location from '" & sadsipath & "' " _
& "where objectClass='computer'"
[/tt]
- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top