troubleshooting Question

Visual Basic command help please

Avatar of scroskey
scroskey asked on
Visual Basic ClassicMicrosoft Development
17 Comments1 Solution862 ViewsLast Modified:
I need to know how to pass information from a command to a variable in visual basic.  For example:

From a dos window if you type dsquery user -name <username>
You will get the result on the screen.  If you type

dsquery user -name <username> >c:file.txt

the output will go to the file listed.

I am trying to write a program that uses the dsquery user result to then execute a dsmove command.  What I have is this (but it does not work ...nothing happens)

' build the dsquery command with output to a file and shell it
        q$ = "dsquery.exe user -name " + Text1.Text + " >c:query.txt"
        Shell (q$)        ' (this shel does nothing and the file is not created)
        Open "c:\query.txt" For Input As #1       '(error file does not exist.)
            Input #1, c$
        c$ = Chr$(34) + c$ + Chr$(34)
 ' finds the first "," in the string
        For x = 1 To Len(c$)
            If Mid$(c$, x, 1) = "," Then
                If z = 0 Then z = x
            End If
' simply takes out the ou that I want to move out of
        cc$ = Chr$(34) + Right$(c$, Len(c$) - z)
        cc$ = Left$(cc$, 8) + Right$(cc$, 29) + Chr$(34)
' build the dsmove command and shell it  

        q$ = "dsmove " + c$ + "-newparent " + cc$
        a = Shell(q$)  ' this does not work even w/ information manually added to a query.txt file

My query result should look like this in the query.txt file...


the dsmove command should look like this:

C:\>dsmove "CN=14218,ou=2009,ou=no-internet,ou=students,dc=mcs,dc=local" -newparent "ou=2009,ou=students,dc=mcs,dc=local"

Any help would be GREATLY APPRECIATED!  I have 5000+ students that started school 2 days ago and are strting to bring back computer use forms so they can have internet acces.  I have a mess on my hands at the moment and am looking for a way to get them access quickly.  

The reason for the sdquery is so I can find out what OU the student is in  ie 2009 (freshman) 2008 (sophmore) etc  

Thank you in advance for any help you can give me.

Scott Croskey
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 17 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 17 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros