James
James

Reputation: 17

Visual Basic CMD Script

Im having trouble with visual basic. Its ment to go run a cmd script when a button is pressed however at the moment it doesn't do anything? I want to try and put values from a text box in some sections when its working but if someone could point me to where im going wrong that would be great!

AAAAA=First Name BBBBB=Last Name

UPDATED Code:

    Private Sub Button_Click(sender As Object, e As EventArgs) Handles Button.Click
    Dim Command As String

    'creating home diretorys'
    Command = "mkdir \\bw-file-01\student$\EY{year}\APPTesting"
    Command = Replace(Command, "{year}", Year.Text)
    MsgBox("Direcotry has been made in" & Year.Text & "file path")

    'setting up account'

    Command = "dsadd user ""cn={fstname}.{lstname},ou=New_users,ou=students,ou=users," & _
      "ou=Broadwater School,dc=broadwater,dc=surrey,dc=sch,dc=uk"" " & _
      "-disabled yes -pwd password -mustchpwd yes -desc {desr} -homedirectory {filepath} -homedrive {homedrive} -email {fstname}.{lstname}@broadwater.surrey.sch.uk -upn ""{fstname}{lstname}@broadwater.surrey.sch.uk"" " & _
      "-fn ""{fstname}"" -ln ""{lstname}"" -Display ""{fstname} {lstname}"""

    Command = Replace(Command, "{fstname}", Firstnamebox.Text)
    Command = Replace(Command, "{lstname}", Surnamebox.Text)
    Command = Replace(Command, "{desr}", desr.Text)
    Command = Replace(Command, "{year}", Year.Text)
    Command = Replace(Command, "{homedrive}", "H:")
    Command = Replace(Command, "{filepath}", "\\bw-file-01\student$\EY2014\APPTesting")

    MsgBox("Account has been made in the" & Year.Text & "group")

    Shell("cmd /c" & Command, 1, True)


End Sub

Upvotes: 0

Views: 173

Answers (1)

Tim Williams
Tim Williams

Reputation: 166181

Command = "dsadd user ""cn=AAABBBB,ou=New_users,ou=students,ou=users," & _
          "ou=Broadwater School,dc=broadwater,dc=surrey,dc=sch,dc=uk"" " & _
          "-disabled yes -pwd changeme -mustchpwd yes -upn ""AAABBBB"" " & _
          "-fn ""AAAAAAAA"" -ln ""BBBBBBBB"" -Display ""AAAAAAAA BBBBBBBB"""

EDIT: if you want to substitute parts of this command with specific text then I prefer the token-replacement approach over a long string of concatenations.

E.g.

Command = "dsadd user ""cn={foo},ou=New_users,ou=students,ou=users," & _
          "ou=Broadwater School,dc=broadwater,dc=surrey,dc=sch,dc=uk"" " & _
          "-disabled yes -pwd changeme -mustchpwd yes -upn ""{bar}"" " & _
          "-fn ""AAAAAAAA"" -ln ""BBBBBBBB"" -Display ""AAAAAAAA BBBBBBBB"""

Command = Replace(Command, "{foo}","something")
Command = Replace(Command, "{bar}","somethingelse")

Upvotes: 1

Related Questions