Press F3 after 15 minutes VB script

I'm in need of a code which will do exactly the following:

If the file in the following location (c:\playlist.txt) has NOT been modified within the last 15 minutes, then press the F3 key , then 10 seconds later the F3 key is pressed a second time.

I need the code to then wait 1 minutes before looping.

I need it to be able to be written into a ".vbs" file which is double clicked to open.

Any help would be greatly appreciated.
Who is Participating?
Daz_1234Connect With a Mentor Commented:

The script below does exactly what you asked.

Comment out the popups on lines 19 and 24 they are there for testing.


Option Explicit

Dim fso, wshShell, strFile, dtmLastModified

Set fso = CreateObject("Scripting.FileSystemObject")
Set wshShell = CreateObject("WScript.Shell")

strFile = "c:\playlist.txt"

If Not fso.FileExists(strFile) Then
    MsgBox "Error: File '" & strFile & "' cannot be found.", vbCritical + vbSystemModal, "File Not Found"
    WScript.Quit 1
End If

    dtmLastModified = fso.GetFile(strFile).DateLastModified
    '# Check if file was modified in the last 15 minutes ...
    If DateDiff("n", dtmLastModified, Now()) > 15 Then
        wshShell.Popup "Sending first F3", 2
        '# Now send F3 ...
        wshShell.SendKeys "{F3}"
        '# Now wait 10 seconds ...
        WScript.Sleep 10000  '# 10 seconds
        wshShell.Popup "Sending second F3", 2
        '# Now send another F3 ...
        wshShell.SendKeys "{F3}"
    End If
    '# Wait 60 seconds before checking again ...
    WScript.Sleep 60000  '# 60 seconds
Loop Until fso.FileExists("c:\stop.txt") '# Will loop forever unless a c:\stop.txt exists or kill WScript.exe task to end

MsgBox "Found c:\stop.txt ... Exiting."

Open in new window

kakashisharingunAuthor Commented:
absolutely perfect - thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.