我在使用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
答案 0 :(得分: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")