bat的執行





頁 : 1 [2] 3 4 5

mis339
2010-05-27, 09:55 AM
sleep要另外準備,不過執行起來比較簡單。
目前網路上的教法大多是用ping或choice,我目前也都是用ping,雖然不是很準,但是「大致上」是OK啦。

ping 192.168.8.8 -n 4 -w 300
192.168.8.8是個不存在的IP,請自訂。這樣大概會停個5秒左右
要停10秒左右請下
ping 192.168.8.8 -n 8 -w 300
以此類推

所以我的要求,目前做法是開機執行批次檔內容如下:
--------------------
@echo off
start /wait ping 192.168.8.8 -n 240 -w 300
start /wait a.bat
start /wait ping 192.168.8.8 -n 48 -w 300
start /wait b.bat
start /wait ping 192.168.8.8 -n 240 -w 300
start /wait c.bat
--------------------

只是想看看有沒有更好的做法,謝謝大家的回應。




tvirus
2010-05-27, 12:02 PM
我是覺得...還是用sleep比較乾脆 Orz
附檔是從Windows Server 2003 Resource Kit Tools (http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd)抽出來的sleep.exe

FYI
2010-05-27, 02:16 PM
I'll ask windata or pcboy to write VBScript or Delphi for me.

bx2aa
2010-05-27, 02:24 PM
sleep要另外準備,不過執行起來比較簡單。
目前網路上的教法大多是用ping或choice,我目前也都是用ping,雖然不是很準,但是「大致上」是OK啦。

ping 192.168.8.8 -n 4 -w 300
192.168.8.8是個不存在的IP,請自訂。這樣大概會停個5秒左右
要停10秒左右請下
ping 192.168.8.8 -n 8 -w 300
以此類推

所以我的要求,目前做法是開機執行批次檔內容如下:
--------------------
@echo off
start /wait ping 192.168.8.8 -n 240 -w 300
start /wait a.bat
start /wait ping 192.168.8.8 -n 48 -w 300
start /wait b.bat
start /wait ping 192.168.8.8 -n 240 -w 300
start /wait c.bat
--------------------

只是想看看有沒有更好的做法,謝謝大家的回應。
ping 不準, 那就用準一點的 %time%
@ECHO OFF
CLS
set t=%time%
set tm=%t:~3,2%
set ts=%t:~6,2%
set /A tm1=%tm%+1
if /I %tm1% GEQ 60 set /A tm1=%tm1%-60
if %tm1%==0 set tm1=00
if %tm1%==1 set tm1=01
if %tm1%==2 set tm1=02
if %tm1%==3 set tm1=03
if %tm1%==4 set tm1=04
if %tm1%==5 set tm1=05
if %tm1%==6 set tm1=06
if %tm1%==7 set tm1=07
if %tm1%==8 set tm1=08
if %tm1%==9 set tm1=09
echo %t%
:min
if NOT %tm1%==%time:~3,2% goto min
:sec
if NOT %ts%==%time:~6,2% goto sec
echo %time%
pause

如果要更準請自行增加 if ...... GEQ %time:~9,2% 應該不差那不到一秒吧!

FYI
2010-05-27, 02:38 PM
ping 不準, 那就用準一點的 %time%
Index of /authors/VA007219/sleep (http://hp.vector.co.jp/authors/VA007219/sleep/)
WindowsにおけるSleep(1)の精度について (http://hp.vector.co.jp/authors/VA007219/rtc_pic.html)

sleep.exe and sleep.vbs (http://www.vector.co.jp/soft/win95/util/se282254.html) Windows 95/98/Me/NT/2000/XP win32 API Sleep() C source code; MS-DOS kbhit() & _dos_gettime(); Windows Script Host WScript.Sleep() vbs source code (MS-DOS,Windows)

VA007219 ソフトウェアの配布 dfd64, diskmap, dkclear, SDFMach (http://hp.vector.co.jp/authors/VA007219/)

琥珀
2010-05-27, 11:39 PM
等待十分鐘的範例:

echo %time%
ping localhost -n 601 > nul
echo %time%

如果系統或網路不忙碌,使用這個指令,效果較好。
ping 192.168.8.8 -n 4 -w 300
192.168.8.8是個不存在的IP,請自訂。這樣大概會停個5秒左右
要停10秒左右請下
ping 192.168.8.8 -n 8 -w 300
以此類推

mis339
2010-05-28, 02:18 AM
呵,謝謝大家,看來大家都還沒放棄批次檔!

windata
2010-05-28, 01:08 PM
comA_delayTime = 3
comB_delayTime = 6
comC_delayTime = 3
Set objShell = CreateObject("WScript.Shell")

WScript.Sleep( 1000 * comA_delayTime )
objShell.Run "%COMSPEC% /k ipconfig"

WScript.Sleep( 1000 * comB_delayTime )
objShell.Run "%COMSPEC% /k nslookup 127.0.0.1"

WScript.Sleep( 1000 * comC_delayTime )
objShell.Run "%COMSPEC% /k ping 127.0.0.1"

以 .vbs 存在,在 ms 環境應該都可以用

bx2aa
2010-05-28, 03:38 PM
檔案 run.bat 內容
set t=%time%
set th=%t:~0,2%
set /A tm=%t:~3,2%+5
:check
if /I %tm% GEQ 60 set /A tm=%tm%-60 && set /A th=%th%+1 && goto check
:check1
if /I %th% GEQ 24 set /A th=%th%-24 && goto check1
at %th%:%tm% "A.bat"

檔案 A.bat 內容
start /wait test.exe
set t=%time%
set th=%t:~0,2%
set /A tm=%t:~3,2%+1
:check
if /I %tm% GEQ 60 set /A tm=%tm%-60 && set /A th=%th%+1 && goto check
:check1
if /I %th% GEQ 24 set /A th=%th%-24 && goto check1
at %th%:%tm% "B.bat"

檔案 B.bat 內容
start /wait test1.exe
set t=%time%
set th=%t:~0,2%
set /A tm=%t:~3,2%+5
:check
if /I %tm% GEQ 60 set /A tm=%tm%-60 && set /A th=%th%+1 && goto check
:check1
if /I %th% GEQ 24 set /A th=%th%-24 && goto check1
at %th%:%tm% "C.bat"

以上沒測試過只是想了一下, 可能還要修改一下.

bx2aa
2010-05-28, 04:17 PM
sleep1min.cs <====== 休息一分鐘


using System;
class sleep
{
static void Main()
{
System.Threading.Thread.Sleep(60000);
}
}

================================================
c:\windows\Microsoft.NET\Framework\v1.1.????\csc sleep1min.cs
c:\windows\Microsoft.NET\Framework\v2.0.?????\csc sleep1min.cs
c:\windows\Microsoft.NET\Framework\v3.5\csc sleep1min.cs
================================================

將 60000*5 = 300000 休息 5 分鐘