【问题标题】:Visual Basic CMD ScriptVisual Basic CMD 脚本
【发布时间】:2014-10-08 10:41:13
【问题描述】:

我在使用 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

【问题讨论】:

    标签: vba cmd basic


    【解决方案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"""
    

    编辑:如果您想用特定文本替换此命令的部分内容,那么我更喜欢令牌替换方法而不是一长串串联。

    例如

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

    【讨论】:

    • 太好了,谢谢!我已经对其进行了调整以做一些额外的事情,但是当我尝试将驱动器映射到它时,它什么也没做,只是崩溃了……我哪里出错了?
    • 尝试引用文件路径。
    • 我试过引用文件路径,但它仍然不起作用
    • 抱歉,我只能建议这些
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多