在Windows Vista上,您具有TIMEOUT和SLEEP命令,但是要在Windows XP或Windows Server 2003上使用它们,则需要Windows Server 2003资源工具包。
在这里,您可以很好地了解其他睡眠方式(ping方法是最受欢迎的方法,因为它可以在每台Windows机器上使用),但是(至少)没有提到(至少)一种使用W32TM
(时间服务)命令的睡眠方法:
w32tm /stripchart /computer:localhost /period:1 /dataonly /samples:N >nul 2>&1
在此处应将N替换为要暂停的秒数。此外,它无需任何先决条件即可在每个Windows系统上运行。
也可以使用Typeperf:
typeperf "\System\Processor Queue Length" -si N -sc 1 >nul
使用mshta和javascript(可在一秒钟内用于睡眠):
start "" /wait /min /realtime mshta "javascript:setTimeout(function(){close();},5000)"
这应该更加精确(等待一秒钟)-自编译可执行文件依赖于.net
:
@if (@X)==(@Y) @end /* JScript comment
@echo off
setlocal
::del %~n0.exe /q /f
::
:: For precision better call this like
:: call waitMS 500
:: in order to skip compilation in case there's already built .exe
:: as without pointed extension first the .exe will be called due to the ordering in PATEXT variable
::
::
for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do (
set "jsc=%%v"
)
if not exist "%~n0.exe" (
"%jsc%" /nologo /w:0 /out:"%~n0.exe" "%~dpsfnx0"
)
%~n0.exe %*
endlocal & exit /b %errorlevel%
*/
import System;
import System.Threading;
var arguments:String[] = Environment.GetCommandLineArgs();
function printHelp(){
Console.WriteLine(arguments[0]+" N");
Console.WriteLine(" N - milliseconds to wait");
Environment.Exit(0);
}
if(arguments.length<2){
printHelp();
}
try{
var wait:Int32=Int32.Parse(arguments[1]);
System.Threading.Thread.Sleep(wait);
}catch(err){
Console.WriteLine('Invalid Number passed');
Environment.Exit(1);
}