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

I have a webpage hosted on a Windows box that I need to assure gets loaded at least once/day. My current plan is to create a scheduled task that opens Internet Explorer and hits the URL:

"C:\Program Files\Internet Explorer\iexplore.exe" myurl.com/script_to_run_daily.aspx

This was simple to setup and works fine, but it strikes me as a hack because Internet Explorer actually has to open and hit this URL. I don't need any input back from this page, it simply stores cached data in files when it's hit.

Is there a slicker way of doing this? In case it matters, this is a VB.net site.

Thanks in advance!


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, False
oHTTP.send ""
set oStream = createobject("adodb.stream")
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
oStream.type = adTypeBinary
oStream.open
oStream.write oHTTP.responseBody
oStream.savetofile sDestFolder & sImageFile, adSaveCreateOverWrite
set oStream = nothing
set oHTTP = nothing
WScript.Echo "Done..."

This SuperUser.com answer is much simpler.

cmd /c start http://example.com/somePage.html

More specifically, here's how it looks in a Windows Scheduled Task:

enter image description here

Although, this likely runs the default configured browser in the background. If it must be IE, then that should be configured. This is likely the best option. It's good to have a solution which runs directly as an Action step of the Task. All the information is right there. Even better if it's terse, so you can see most of the command without scrolling across the textbox.

WGET / CURL - good alternative

If anything, WGET would be a good alternative to cmd..start..url. I'm not the first to think of this. The downside is you have to download WGET for Windows for it to work - it isn't an out-of-the-box solution. But WGET is lighter and importantly gives you more power. You can send lots of other types of URL calls. This includes different HTTP methods such as POST, custom Headers and more. Curl is a good option, instead of Wget - they have different sets of features, many overlapping.

PowerShell - not recommended

PowerShell, might be considered a "lighter" option, but you're also loading up a PowerShell (.Net AppDomain) which has a bit of lag, and also the command is a lot longer, and therefore harder to remember if you're doing this regularly. So PowerShell isn't the best option.

VBScript - not recommended

Clearly, VBScript is less recommendable. You have so much more you would need to remember, and the script is quite large. Unless you have other steps which warrant a script, don't have a completely separate resource just to do something you could have accomplished directly within a Scheduled Task.

Also, see similar questions:

  • https://superuser.com/questions/321215/how-can-i-open-a-url-on-a-schedule-in-the-default-browser
  • Simple-as-possible task schedule to call web page