windows – 使用PowerShell每隔x秒运行一个批处理文件

我想使用 Windows PowerShell脚本每隔x秒运行批处理文件.所以这是一遍又一遍地运行的同一个批处理文件.

我做了一些看,但找不到我想要的东西.这是我希望在Windows XP机器上运行的东西.我曾经多次使用过Windows Scheduler来获得类似的东西,但出于某种原因,Windows Scheduler只运行一次……然后就没有了.我也不想让批处理文件调用本身,因为它会在运行很多次后出错.

只需在while循环中调用批处理文件即:
$period = [timespan]::FromSeconds(45)
$lastRunTime = [DateTime]::MinValue 
while (1)
{
    # If the next period isn't here yet,sleep so we don't consume cpu
    while ((Get-Date) - $lastRunTime -lt $period) { 
        Start-Sleep -Milliseconds 500
    }
    $lastRunTime = Get-Date
    # Call your batch file here
}

相关文章

Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...
Windows文件操作基础代码 Windows下对文件进行操作使用的一段...
Winpcap基础代码 使用Winpcap进行网络数据的截获和发送都需要...
使用vbs脚本进行批量编码转换 最近需要使用SourceInsight查看...