0

我在 VBS 中编写了以下代码以使用用户名和密码打开一个应用程序(我在 Windows 10 上)。

   Title="Menu"
    message = "Select your task"&vbcr&vbcr&_

    "1 - T "&vbcr&_
    "        "&vbcr&_
    "2 - A "&vbcr&_
    "        "&vbcr&_
    "3 - M "&vbcr&_
    "        "&vbcr&_
    "4 - Exit "
           
    Do
       response = InputBox(message,Title,4)
        If response = "" Then WScript.Quit  
        If IsNumeric(response) Then Exit Do 
        MsgBox "enter numeric values only"
    Loop
    
          
    
    Select Case response 
    Case 1 Run(1)
    Case 2 Run(2)
    Case 3 Run(3)
    Case 4 Run(4)
    end Select
    
    
    
    Sub Run(var)
    
    Set WshShell = WScript.CreateObject("WScript.Shell")
    set objshell = WScript.CreateObject( "WScript.Shell")
        
        Select Case var
        Case 1 
    
    objShell.Run("""C:\Program Files\pab.exe""")                'for application open
    objshell.AppActivate (apptitle)
  '  objshell.AppActivate ("pab.exe")        

    WScript.Sleep 400
   WshShell.SendKeys "{ENTER}"                                    'send key when application open
        
    WScript.Sleep 400
    WshShell.SendKeys "ca"                                      'user name of application
    
    WScript.Sleep 400
    WshShell.SendKeys "{ENTER}"
    
    
    WshShell.SendKeys "ca1"                                        'password of application  
    WshShell.SendKeys "{ENTER}"
    
    WScript.Sleep 400
    
    WshShell.SendKeys "xxxx"                                        'another password  
    WshShell.SendKeys "{ENTER}"
    
            REM WshShell.SendKeys "%S"
              
    Set objshell= nothing
    Set WSHShell = Nothing
    
        Case 4 wscript.quit()
    End select
End Sub 

问题是当我从菜单中选择一个选项并按 OK 按钮时,焦点转到菜单上。所以几乎我无法使用用户名和密码执行应用程序。谁能帮我弄清楚如何将焦点设置在 PAB.EXE 而不是 MENU 上?

干杯!

4

0 回答 0