views:

349

answers:

5

At a certain time each day, I'd like my browser to pop open a tab to a certain URL.

My goals:

  1. be able to set the URL from the scheduled task
  2. use the default browser (rather than hard-coding it)

I can't seem to accomplish both of these goals at once. I'll post my partial solutions as answers, but I'm hoping someone will have something better.

A: 

This solution doesn't allow me to set the URL from the scheduled task:

Create a .url file pointing to the URL I want.

Create a .vbs script that opens the URL:

CreateObject("Wscript.Shell").Run """example.url""", 0, False

Create the scheduled task to run the .vbs script.

Jeremy Stein
A: 

This solution is hard-coded to Firefox:

Create the scheduled task with this URL:

"C:\Program Files\Mozilla Firefox\firefox.exe" -new-tab http://example.com
Jeremy Stein
+3  A: 

I believe if you run:

cmd /c start http://example.com

that opens the default browser (or a new tab therein) to the given url.

Notes from questioner:

Good suggestion, dmb. Since I didn't want a command window to pop up, I used a VBS file. I created OpenUrl.vbs:

CreateObject("Wscript.Shell").Run "cmd /c start " & Wscript.Arguments.Item(0), 0, False

Then I called it from my scheduled task with this command:

wscript.exe "C:\Path\To\Script\OpenUrl.vbs" http://example.com
dmb
Thanks. I added my notes to the answer.
Jeremy Stein
+1  A: 

Well, you could just create the url file from your script :

Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile= fso.CreateTextFile("c:\example.url", True)
MyFile.WriteLine("[InternetShortcut]")
MyFile.WriteLine("URL=http://stackoverflow.com/questions/2655253/scheduled-task-to-open-url")
MyFile.Close
FenchKiss Dev
I always assumed those were binary files. I never thought to inspect their contents. Thanks!
Jeremy Stein
A: 

One additional thing to note for the FF solution - if your URL has ampersands in it - you may need to escape those in Scheduled tasks using the caret ^& character.

Oops - this is wrong. The ^ was needed to escape the Ampersand when testing the link in a CMD window - but is okay in the actual Scheduled Task.

PatBoule