PowerShell 定时执行.Net(C#)程序的方法
可能也有其他方法,比如用 WGet 等等,但是 推荐用 PowerShell ,为什么呢,因为 PowerShell 太强大呗
PowerShell 语法(demo1.ps1):
$date = Get-Date;
$beginTime = 2 * 60 ;
$endTime = 2 * 60 + 11;
$minuteCount = $date.hour * 60 + $date.minute
#if the time is right
if(($minuteCount -le $endTime ) -and ($minuteCount -ge $beginTime ))
{
#send request
$webClient = new-object System.Net.WebClient;
$webClient.Headers.Add("user-agent","PowerShell Script");
$webClient.Headers.Add("Referer","PowerShell Script");
$url = "https://www.jb51.net/enAdmin/Handler/Listen_cms.ashx?code=listen_cms_20111130876";
$message = $webClient.DownloadString($url);
#write log
write("Message:"+$message);
}
else
{
write("Not Update");
}
sleep 5
Bat 语法(demo1.bat):
powershell %~sdp0Listen-Cms.ps1
sleep 5
上一篇:Asp.net MVC利用knockoutjs实现登陆并记录用户的内外网IP及所在城市(推荐)
栏 目:.NET代码
本文标题:PowerShell 定时执行.Net(C#)程序的方法
本文地址:http://www.codeinn.net/misctech/189052.html