Recommended method for loading a URL via a scheduled task on Windows

As pointed out by Remus Rusanu, PowerShell would be the way to go. Here’s a simple one-liner that you can use to create a scheduled task, without needing to write a separate .ps1 file:

powershell -ExecutionPolicy Bypass -Command
    Invoke-WebRequest 'http://localhost/cron.aspx' -UseBasicParsing

Note that line breaks are added only for clarity in all of these command lines. Remove them before you try running the commands.

You can create the scheduled task like this: (run this from an elevated command prompt)

schtasks /create /tn "MyAppDailyUpdate"
    /tr "powershell -ExecutionPolicy Bypass -Command
        Invoke-WebRequest 'http://localhost/cron.aspx' -UseBasicParsing"
    /sc DAILY /ru System

The above will work for PowerShell 3+. If you need something that will work with older versions, here’s the one-liner:

powershell -ExecutionPolicy unrestricted -Command
    "(New-Object Net.WebClient).DownloadString(\"http://localhost/cron.aspx\")"

You can create the scheduled task like this: (from an elevated command prompt)

schtasks /create /tn "MyAppDailyUpdate"
    /tr "powershell -ExecutionPolicy unrestricted -Command
        \"(New-Object Net.WebClient).DownloadString(\\\"http://localhost/cron.aspx\\\")\""
    /sc DAILY /ru System

The schtasks examples set up the task to run daily – consult the schtasks documentation for more options.

Leave a Comment