2014-10-08 66 views
0

我在使用visual basic時遇到了麻煩。當按下按鈕時,它的運行腳本會運行一個cmd腳本,但目前它沒有做任何事情?我想嘗試在某些部分的文本框中輸入值,但如果有人可以指出我會在哪裏出錯,那會很棒!Visual Basic CMD腳本

AAAAA =名字 BBBBB =姓

更新的代碼:

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 

回答

1
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""" 

編輯:如果你想替換特定的文本命令的部分,然後我喜歡令牌的通過長串連接替代方法。

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") 
+0

非常感謝!我調整它做一些額外的事情,但當我試圖映射驅動器到它它沒有做任何事,只是崩潰了...任何想法,我即將出錯? – James 2014-10-09 13:29:03

+0

嘗試引用文件路徑。 – 2014-10-09 15:50:12

+0

我嘗試過引用文件路徑,它不起作用 – James 2014-10-12 09:32:16