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

Visual Basic way to capture DSQUERY Results

Status
Not open for further replies.

DesertDBA

Programmer
Jan 27, 2004
4
US
I need to change users passwords in Active Directory using the dsmod command at the command line. I have that part working, but I have a problem. Here is the DSmod portion :
Dim ProcessArgument As String
ProcessArgument = "User ""cn=" + Convert.ToString(UserName).Trim + ",ou=place,ou=Users,ou=MainName, dc=Domain, dc=org"" -pwd " + UnEncryptPassword.Trim

Dim MyProcess As New System.Diagnostics.Process
MyProcess.StartInfo.CreateNoWindow = True
MyProcess.StartInfo.UseShellExecute = True
MyProcess.StartInfo.WorkingDirectory = "C:\Windows\system32"
MyProcess.StartInfo.FileName = "dsmod.exe"
MyProcess.StartInfo.Arguments = ProcessArgument
MyProcess.Start()

The problem is that the ou=place can be different for each employee. I am trying to use dsquery to retreive that information. The command runs, but I am unable to capture the result back to the program. Here is the snip I am using for the dsquery :
Dim ProcessArgument2 As String
ProcessArgument2 = " User -samid " + Convert.ToString(UserName).Trim + " >> c:\usertest.txt "
Dim MyProcess2 As New System.Diagnostics.Process
MyProcess2.StartInfo.CreateNoWindow = True
MyProcess2.StartInfo.UseShellExecute = True
MyProcess2.StartInfo.WorkingDirectory = "C:\Windows\system32"
MyProcess2.StartInfo.FileName = "dsquery"
MyProcess2.StartInfo.Arguments = ProcessArgument2
MyProcess2.StartInfo.RedirectStandardOutput = True

MyProcess2.Start()

Any ideas would be helpful.

- Jason
 

This line of code:

ProcessArgument2 = " User -samid " + Convert.ToString(UserName).Trim + " >> c:\usertest.txt "

indicates that the output is being redirected to a text file called usertest.txt. Does this work? Can you parse the text file to get the data you need?

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
No that line does not work, it does not create the txt file.

- Jason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top