0
votes

I 've created an application with Visual Basic, containing a menu bar. Using a menu bar in the application, I can start VB scripts, which works fine.

The next step is to schedule the tasks daily, so I don't have to manually start the scripts.

I would like to use the Task Scheduler to perform the tasks daily and wrote an .vbs script which I scheduled in the Task Scheduler. Testing the script by manually starting the task from Task Scheduler works. But when scheduled (eg for the next morning) it fails: the program is started, but the next step is not performed.. I'am using a laptop, powered at all times, sleeping mode is off, Windows10

My vbs script:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys("{F13}") 
WScript.Sleep 10*1000 '10 sec
WshShell.Run  "C:\360_Stuurprogramma\bin\Debug\360_Stuurprogramma.exe"
WScript.Sleep 5*1000 '5 sec
WshShell.AppActivate """360 Applicatie"" -p1 -c"
WScript.Sleep 20*1000
wshShell.SendKeys "^S"
WScript.Sleep 20*60*1000 '20 min, maximum time needed to perform the job
WshShell.Run "taskkill /f /im 360_Stuurprogramma.exe", , True
1
Take a look at this answer perhaps help you to make a scheduled task !Hackoo

1 Answers

0
votes

Only programs with a foreground GUI can set the active window. A program started by the active window has two seconds to show a GUI to become the foreground window. The full rules are here - https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setforegroundwindow NB Task Scheduler will never be the foreground window.

The system restricts which processes can set the foreground window. A process can set the foreground window only if one of the following conditions is true:

•The process is the foreground process.

•The process was started by the foreground process.

•The process received the last input event.

•There is no foreground process.

•The process is being debugged.

•The foreground process is not a Modern Application or the Start Screen.

•The foreground is not locked (see LockSetForegroundWindow).

•The foreground lock time-out has expired (see SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo).

•No menus are active.

An application cannot force a window to the foreground while the user is working with another window. Instead, Windows flashes the taskbar button of the window to notify the user.