PowerShell 定时执行.Net(C#)程序的方法
程序员文章站
2023-12-17 19:26:04
可能也有其他方法,比如用 wget 等等,但是 推荐用 powershell ,为什么呢,因为 powershell 太强大呗
powershell 语法(demo1.p...
可能也有其他方法,比如用 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 = "//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