Vbscript VBA暂停、恢复并在后台运行

Vbscript VBA暂停、恢复并在后台运行,vbscript,notepad,Vbscript,Notepad,我对VBS非常陌生,希望有人能给我一些建议。我正在通过记事本编写VBS脚本,但在执行以下操作时遇到问题: 在用户通过输入框输入请求的信息后暂停然后恢复的脚本 脚本复制输入的数据,然后粘贴到应用程序窗口中 脚本运行时,在执行下一个脚本之前等待运行完成 用户输入密码后,隐藏窗口并让其在后台运行,以允许用户继续执行其他任务 脚本如下: Set objShell = WScript.CreateObject("WScript.Shell") objShell.Exec "app location" Do

我对VBS非常陌生,希望有人能给我一些建议。我正在通过记事本编写VBS脚本,但在执行以下操作时遇到问题:

  • 在用户通过输入框输入请求的信息后暂停然后恢复的脚本
  • 脚本复制输入的数据,然后粘贴到应用程序窗口中
  • 脚本运行时,在执行下一个脚本之前等待运行完成
  • 用户输入密码后,隐藏窗口并让其在后台运行,以允许用户继续执行其他任务
  • 脚本如下:

    Set objShell = WScript.CreateObject("WScript.Shell")
    objShell.Exec "app location"
    Do Until Success = True
        Success = objShell.AppActivate("Application")
    Loop
    objshell.Sendkeys "{TAB}{TAB}{TAB}{TAB}{TAB}"
    objShell.SendKeys "*server name*"
    objShell.SendKeys "{enter}"
    
    wscript.sleep 100
    
    strusername=inputbox("Enter your user name","User Name")
    If strusername = "" Then
        Wscript.Quit
    Else
        ObjShell.AppActivate("PuTTY Configuration")
        objshell.SendKeys "+INS", True
        objshell.SendKeys "{enter}"
    
    strpassword=inputbox("Enter your Password","Password")
    If strpassword = "" Then
        Wscript.Quit
    Else
    
        ObjShell.AppActivate("PuTTY Configuration")
        objshell.SendKeys "+INS", True
        objshell.SendKeys "{enter}"
    End if
    
    *Resume the script*
    
    ObjShell.Appactivate("application")
    objShell.SendKeys "server name"
    objShell.SendKeys "{enter}"
    
    ObjShell.Appactivate("application")
    objShell.SendKeys "*I need the password entered earlier to be copied and paste here*"
    objShell.SendKeys "{enter}"
    
    wscript.sleep 1000
    
    ObjShell.Appactivate("*application*")
    objShell.SendKeys "server name"
    objShell.SendKeys "{enter}"
    
    wscript.sleep 6000
    
    and it keeps going until it's finished then does:
    
    ObjShell.Appactivate("*application*")
    objShell.SendKeys "exit"
    objShell.SendKeys "{enter}"
    objShell.SendKeys "exit"
    objShell.SendKeys "{enter}"
    objShell.SendKeys "exit"
    objShell.SendKeys "{enter}"
    
    我也尝试过:

    do while not wscript.StdIn.AtEndofLine
      input=input & wscript.StdIn.ReadLine
     Loop
    do while not wscript.StdIn.AtEndofLine
      input=input & wscript.StdIn.ReadLine
     Loop
    wscript.sleep 1000
    
    ObjShell.Appactivate("*application*")
    objShell.SendKeys "server name"
    

    SendKeys是可怕的,注定要失败。如果要通过脚本启动Putty,只需使用输入框从用户处收集服务器/密码,然后将其作为参数传递给Putty.exe,如
    c:\path\Putty.exe-pw passworduser@server
    。但是,当然,问题是你为什么要这么做呢?我有大约20个vbs sendkeys脚本,我至少每分钟使用一次,通常更多,用于PuTTY。他们99%的时间都在工作。您的脚本需要cscript才能工作,因为您正在使用控制台功能。请后退一步,描述您试图解决的问题,而不是您认为的解决方案。你想通过这样做来实现什么?抱歉,我应该更清楚:我想做的是自动化一个过程,用户可以在后台运行整个脚本。所需的唯一交互是用户输入用户名和密码,然后其余的将自行处理。我已经能够从脚本中很好地运行整个过程,只想对其进行优化,使其更加高效。我的问题是能够让用户输入用户名和密码,然后运行下一个命令,而不是使用“wscript.sleep”命令。PuTTY套件包括具有用户名和密码参数的命令行程序。