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 r...
可能也有其他方法,比如用 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 = "http://www./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