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

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.


You can schedule a PowerShell script. PS is pretty powerfull and gives you access to the entire .Net Framework, plus change. Here is an example:

$request = [System.Net.WebRequest]::Create("http://www.example.com")$response = $request.GetResponse()$response.Close()


Another option is VB Script. For example (save as file.vbs):

sSrcUrl = "http://yourdomain.com/yourfile.aspx"sDestFolder = "C:\yourfolder\"sImageFile = "filename.txt"set oHTTP = WScript.CreateObject("MSXML2.ServerXMLHTTP")oHTTP.open "GET", sSrcUrl, FalseoHTTP.send ""set oStream = createobject("adodb.stream")Const adTypeBinary = 1Const adSaveCreateOverWrite = 2oStream.type = adTypeBinaryoStream.openoStream.write oHTTP.responseBodyoStream.savetofile sDestFolder & sImageFile, adSaveCreateOverWriteset oStream = nothingset oHTTP = nothingWScript.Echo "Done..."