How to schedule a .vbs script with UI elements?

2019-09-06 20:25发布

I am new to vb scripting. I need to schedule a windows task which can run a vbs file. The script opens up a application from its shortcut, feeds username and password and performs login. In other words, I need to automate the restart process. The scripts runs as expected when opened manually but scheduler cannot not run it. I think the problem is with those UI elements(used for login). Please suggest how to get through it. Thank you!

1条回答
时光不老,我们不散
2楼-- · 2019-09-06 21:18

AppActivate does not itself restore the window if it is for some reason minimized.

You can try to find the reason why it's minimized (maybe it has something to do with the batch calling the vbs calling the application, I cannot really say) or you can try a little hack in the vbscript like the following:

After the AppActivate do a:

oShell.SendKeys "% r"

This is equivalent of Alt+SpaceBar, r so it opens the windows dialog for Maximize, Minimize, Restore options and choses "Restore".

Note that this might only be r on english copies of windows. If you use another Language manually open that menu by pressing Alt+SpaceBar and looking what the actual hotkey on your system is (it would be underlined in the dialog). Afterwards replace the r in the script with whatever hotkey is used in your language.

查看更多
登录 后发表回答