Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use AppActivate to change the active window

Tags:

vbscript

I'm am trying to send some keystrokes to a program. I have some example code below which works fine up until the final {Alt} command. I believe this is due to the window name changing from "Notepad1" to "NotePad2". Could anyone help me change the AppActivate path to "Notepad2" after the objShell.SendKeys "{Enter}" command?

Example:

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "Notepad.exe"
Do Until Success = True
Success = objShell.AppActivate("NotepadPathA")
Loop
objShell.SendKeys "{F1}"
objShell.SendKeys "Secure06**"
objShell.SendKeys "{Enter}"
Shell.SendKeys "{Alt}"
like image 220
David James Avatar asked Sep 15 '25 11:09

David James


1 Answers

  1. You're using Shell on your last line but you haven't defined it. Change it to objShell instead.
  2. To send the Alt key, use "%". For example:

    objShell.SendKeys "%"
    

    You would typically use this in a key combination. For example, to open the File menu in most programs, you would use Alt+F, or:

    objShell.SendKeys "%f"
    
  3. If your window title changes, or you need to activate a new window for whatever reason, just call AppActivate again:

    objShell.AppActivate "My new window title"
    
like image 125
Bond Avatar answered Sep 17 '25 19:09

Bond



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!