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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax problem with VBScript that writes a VBScript...

Status
Not open for further replies.

hoialmen

MIS
Dec 10, 2001
53
US
I am trying to write a VBScript that writes a VBScript out to a *.vbs file(otf). The following is the script that I need my script to generate:

Set cont = GetObject("LDAP://OU=Department, OU=Location, OU=Region, OU=Company, DC=Tree, DC=Forest")
cont.Delete "user", "CN=UserName"


And this is the script that I'm using to write it:

rs.MoveFirst

Do While Not rs.EOF
otf.WriteLine(1, "Set cont = GetObject(", """, "LDAP://OU=", rs.Department, ", OU=", rs.Location, ", OU=", rs.Region, ", OU=Citadel, DC=CCC, DC=CCC", """, ")")
oft.WriteLine(1, "cont.Delete ", """, "user", """, ", ", """, "CN=", rs.UserName, """)
oft.WriteBlankLines(1)

rs.MoveNext


Now, when I try and compile this code, I get an error that says; "Error Source: Microsoft VBScript Compilation error, Error Description: Expected ')' " and it's saying this error occurred on the first "WriteLine" statement.

Is there a VBScript wizzard out there that can see where the problem is or maybe suggest a better way to accomplish what I'm trying to do? I'm assuming that the problem has something to do with all commas, quotation marks and parentheses that I am trying to write into my output script.

Any suggestions will be greatly appreciated.

Thanks!

Nate
 
Try something like this

Dim fso, tf
strDept="dept"
strUsername="UserName"
strLocation="Location"
strregion="region"
strCompany="company"
Set fso = CreateObject("Scripting.FileSystemObject")
Set tf = fso.CreateTextFile("c:\testfile.txt", True)
' Write a line with a newline character.
'tf.WriteLine("Set cont = GetObject(", """, "LDAP://OU=", strDept, ", OU=", rs.Location, ", OU=", rs.Region, ", OU=Citadel, DC=CCC, DC=CCC", """, ")")
' Write three newline characters to the file.

' Write a line.
tf.WriteLine("Set cont=GetObject(" & chr(34) & "LDAP://OU=" & strDept & ",OU=" & strLocation & ",OU=" & strRegion & ",OU=" & strCompany & ",DC=Tree,DC=Forest" & chr(34) & ")")

tf.WriteLine ("cont.Delete " & chr(34) & "user" & chr(34) & "," & chr(34) & "CN=" & strUserName & chr(34) )
'& ""user"" & ", " & ""CN="" & strUser & ""
tf.WriteBlankLines(3)
tf.Close

34 is the ascii for "
chr() will return the character for the given ascii character code
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top