0

so I've been trying to get VLC player to skip to the next file at a specific time (10am). I've got the following script that worked fine for a few days, and then stopped completely.

Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.AppActivate "VLC Media Player" WScript.sleep(200) WshShell.SendKeys "n"

The VBS file itself runs fine, however task scheduler doesn't seem to skip the file when it runs (the vlc window will sometimes flash).

I've tried ignoring login, changing the user to system and setting to run under any network connection, and having a .bat file run the .vbs script. Nothing has worked so far and I feel like I'm going nuts, any help would be hugely appreciated. I have close-to zero knowledge of scripting so I would appreciate things explained if possible.

1
  • In Task Scheduler, click the task, then head to the log tab and see if it actually runs and finishes, or that it gives an error there. This is where you'll find out if the problem is with Task Scheduler or your script afterall.
    – LPChip
    Commented Dec 30, 2023 at 17:11

1 Answer 1

0

Using the application title when calling AppActivate can often produce undesirable results. For example, if you view this SuperUser article in a Chromium browser, AppActivate may mistakenly choose and activate it, since the browser tab title begins with: vlc media player. To avoid this confusion, it is often preferred to grab and use the process ID of the running application instead of its title.

For example:

Dim PID : PID = 0
With GetObject("winmgmts:\\.\root\CIMV2")
    For Each oProc in .ExecQuery("SELECT ProcessID FROM Win32_Process WHERE Name='vlc.exe'", "WQL", 48)
        PID = oProc.ProcessID
        Exit For
    Next
End With

If 0 <> PID Then
    With CreateObject("WScript.Shell")
        .AppActivate PID
        .SendKeys "n"
    End With
End If

Here we are calling WMI to grab the Win32_Process class of the running vlc.exe process -- specifically, its process ID. If successful, use the process ID when calling AppActivate prior to calling SendKeys.

Hope this helps.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .