通过Windows上的计划任务加载URL的推荐方法

时间:2022-05-12 02:32:07

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:

我有一个托管在Windows机器上的网页,我需要确保每天至少加载一次。我目前的计划是创建一个打开Internet Explorer并点击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.

这很容易设置并且工作正常,但它让我感到非常黑客,因为Internet Explorer实际上必须打开并点击此URL。我不需要从该页面返回任何输入,它只是将缓存的数据存储在文件中。

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

这样做有一种更明智的方式吗?万一重要,这是一个VB.net网站。

Thanks in advance!

提前致谢!

7 个解决方案

#1


108  

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:

正如Remus Rusanu所指出的,PowerShell将是最佳选择。这是一个简单的单行程序,您可以使用它创建计划任务,而无需编写单独的.ps1文件:

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

You can create the scheduled task like this:

您可以像这样创建计划任务:

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

This example sets up the task to run daily - consult the schtasks.exe documentation for more options.

此示例将任务设置为每天运行 - 请参阅schtasks.exe文档以获取更多选项。

#2


39  

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:

您可以安排PowerShell脚本。 PS功能非常强大,可让您访问整个.Net Framework,以及更改。这是一个例子:

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

#3


18  

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

另一种选择是VB Script。例如(另存为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..."

#4


9  

As of PowerShell 5.0, curl is an alias for Invoke-WebRequest, so you can create a Scheduled Task as follows:

从PowerShell 5.0开始,curl是Invoke-WebRequest的别名,因此您可以按如下方式创建计划任务:

Action: Start a program
Program/script: powershell
Add arguments: curl http://www.example.com/foo/bar

You can also use Invoke-WebRequest, but curl is more concise.

您也可以使用Invoke-WebRequest,但curl更简洁。

#5


7  

This SuperUser.com answer is much simpler.

这个SuperUser.com的答案要简单得多。

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

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

更具体地说,这是它在Windows计划任务中的外观:

通过Windows上的计划任务加载URL的推荐方法

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.

虽然,这可能会在后台运行默认配置的浏览器。如果它必须是IE,那么应该配置它。这可能是最好的选择。拥有直接作为任务的Action步骤运行的解决方案是一件好事。所有信息都在那里。如果它简洁,那就更好了,所以你可以看到大部分命令而无需滚动文本框。

WGET / CURL - good alternative

WGET / CURL - 很好的选择

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.

如果有的话,WGET将是cmd..start..url的一个很好的替代品。我不是第一个想到这一点的人。缺点是你必须下载WGET for Windows才能工作 - 它不是一个开箱即用的解决方案。但WGET更轻,重要的是给你更多的力量。您可以发送许多其他类型的URL调用。这包括不同的HTTP方法,如POST,自定义标头等。 Curl是一个不错的选择,而不是Wget - 它们具有不同的功能集,许多重叠。

PowerShell - not recommended

PowerShell - 不推荐

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.

PowerShell,可能被认为是一个“更轻”的选项,但你也加载了一个有点滞后的PowerShell(.Net AppDomain),并且命令也要长得多,因此如果你是更难记住经常这样做。所以PowerShell不是最好的选择。

VBScript - not recommended

VBScript - 不推荐

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.

显然,VBScript不太值得推荐。你还需要记住更多,脚本非常大。除非您有其他保证脚本的步骤,否则不要使用完全独立的资源来执行您可以直接在计划任务中完成的任务。

Also, see similar questions:

另外,请看类似的问题:

#6


5  

There are Windows versions of the most common command-line http request tools, such as cURL and wget. You could certainly create a scheduled task that would run one of these. I have also done this from within a Windows Scripting Host script, if you needed to loop or create URL parameters on the fly, or some such.

Windows版本中最​​常见的命令行http请求工具,例如cURL和wget。你当然可以创建一个运行其中一个的计划任务。我也是在Windows Scripting Host脚本中完成此操作,如果您需要动态循环或创建URL参数,或者其他一些。

#7


0  

tried with curl on PowerShell 4.0, curl is an alias for Invoke-WebRequest, so you can create a Scheduled Task as follows:

在PowerShell 4.0上尝试使用curl,curl是Invoke-WebRequest的别名,因此您可以创建一个Scheduled Task,如下所示:

Action: Start a program Program/script: powershell Add arguments: curl http://www.example.com/foo/bar

操作:启动程序程序/脚本:powershell添加参数:curl http://www.example.com/foo/bar

worked like a charm!

像魅力一样工作!

#1


108  

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:

正如Remus Rusanu所指出的,PowerShell将是最佳选择。这是一个简单的单行程序,您可以使用它创建计划任务,而无需编写单独的.ps1文件:

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

You can create the scheduled task like this:

您可以像这样创建计划任务:

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

This example sets up the task to run daily - consult the schtasks.exe documentation for more options.

此示例将任务设置为每天运行 - 请参阅schtasks.exe文档以获取更多选项。

#2


39  

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:

您可以安排PowerShell脚本。 PS功能非常强大,可让您访问整个.Net Framework,以及更改。这是一个例子:

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

#3


18  

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

另一种选择是VB Script。例如(另存为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..."

#4


9  

As of PowerShell 5.0, curl is an alias for Invoke-WebRequest, so you can create a Scheduled Task as follows:

从PowerShell 5.0开始,curl是Invoke-WebRequest的别名,因此您可以按如下方式创建计划任务:

Action: Start a program
Program/script: powershell
Add arguments: curl http://www.example.com/foo/bar

You can also use Invoke-WebRequest, but curl is more concise.

您也可以使用Invoke-WebRequest,但curl更简洁。

#5


7  

This SuperUser.com answer is much simpler.

这个SuperUser.com的答案要简单得多。

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

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

更具体地说,这是它在Windows计划任务中的外观:

通过Windows上的计划任务加载URL的推荐方法

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.

虽然,这可能会在后台运行默认配置的浏览器。如果它必须是IE,那么应该配置它。这可能是最好的选择。拥有直接作为任务的Action步骤运行的解决方案是一件好事。所有信息都在那里。如果它简洁,那就更好了,所以你可以看到大部分命令而无需滚动文本框。

WGET / CURL - good alternative

WGET / CURL - 很好的选择

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.

如果有的话,WGET将是cmd..start..url的一个很好的替代品。我不是第一个想到这一点的人。缺点是你必须下载WGET for Windows才能工作 - 它不是一个开箱即用的解决方案。但WGET更轻,重要的是给你更多的力量。您可以发送许多其他类型的URL调用。这包括不同的HTTP方法,如POST,自定义标头等。 Curl是一个不错的选择,而不是Wget - 它们具有不同的功能集,许多重叠。

PowerShell - not recommended

PowerShell - 不推荐

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.

PowerShell,可能被认为是一个“更轻”的选项,但你也加载了一个有点滞后的PowerShell(.Net AppDomain),并且命令也要长得多,因此如果你是更难记住经常这样做。所以PowerShell不是最好的选择。

VBScript - not recommended

VBScript - 不推荐

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.

显然,VBScript不太值得推荐。你还需要记住更多,脚本非常大。除非您有其他保证脚本的步骤,否则不要使用完全独立的资源来执行您可以直接在计划任务中完成的任务。

Also, see similar questions:

另外,请看类似的问题:

#6


5  

There are Windows versions of the most common command-line http request tools, such as cURL and wget. You could certainly create a scheduled task that would run one of these. I have also done this from within a Windows Scripting Host script, if you needed to loop or create URL parameters on the fly, or some such.

Windows版本中最​​常见的命令行http请求工具,例如cURL和wget。你当然可以创建一个运行其中一个的计划任务。我也是在Windows Scripting Host脚本中完成此操作,如果您需要动态循环或创建URL参数,或者其他一些。

#7


0  

tried with curl on PowerShell 4.0, curl is an alias for Invoke-WebRequest, so you can create a Scheduled Task as follows:

在PowerShell 4.0上尝试使用curl,curl是Invoke-WebRequest的别名,因此您可以创建一个Scheduled Task,如下所示:

Action: Start a program Program/script: powershell Add arguments: curl http://www.example.com/foo/bar

操作:启动程序程序/脚本:powershell添加参数:curl http://www.example.com/foo/bar

worked like a charm!

像魅力一样工作!