2015-02-11 100 views
1

怎樣才能得到一個消息窗口打開,有一個使用批處理文件的計時器? 我試圖做一個批處理文件,打開命令提示符,並做了2個命令後彈出一個消息彈出一個計時器,說自毀在...然後播放聲音,然後關閉 這是我有到目前爲止Cmd提示計時器窗口彈出

:cmd 
set /p cmd=command: 

%cmd% 
echo. 
goto cmd2 

:cmd2 

set /p cmd=command: 

%cmd% 
echo. 
+1

[見這個答案](http://stackoverflow.com/ a/28323363/1683264)的想法。沒有用於從批處理腳本創建警報窗口的本機命令,但是您可以藉助Windows腳本宿主(VBScript或JScript)進行彈出。 – rojo 2015-02-11 04:51:59

回答

2

試試這個 - 只接受一個參數 - 秒到countdown.Should與.bat擴展名保存:

<!-- : 
:: countdown.bat 
@echo off 

if "%~1" equ "" (
    echo seconds not passed 
    exit /b 1 
) 

echo %*|mshta.exe "%~f0"|more 



exit /b %errorlevel% 
--> 

<html> 
<head><title>It's the final countdown</title></head> 
<body> 

<p>Seconds left</p> 
<div id="countdown">--</div> 
<button onclick='quit()'>QUIT</button> 
    <script language='javascript' type="text/javascript"> 
     function parse() { 
       var seconds=0; 
       try { 
        var fso2= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(0); 
        argline=fso2.ReadLine(); 
        var args=argline.split(" "); 
        var seconds=parseInt(args[0]); 
        //var fso= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1); 
        //fso.Write("wait for: " + milliseconds); 
       } catch (err) { 
        errmessage = "cannot get the milliseconds"; 
        var fso= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1); 
        fso.Write(errmessage); 
        close(); 
       } 
       seconds = document.getElementById('countdown').innerHTML=seconds; 
       countdown(); 
     } 

    var seconds; 
    var temp; 

    function countdown() { 
    seconds = document.getElementById('countdown').innerHTML; 
    seconds = parseInt(seconds, 10); 

    if (seconds == 1) { 
     temp = document.getElementById('countdown'); 
     close(); 
     //return; 
    } 

    seconds--; 
    temp = document.getElementById('countdown'); 
    temp.innerHTML = seconds; 
    timeoutMyOswego = setTimeout(countdown, 1000); 
    } 

    //countdown(); 
    window.resizeTo(400,250) 
    parse(); 

     function quit() { 
      close(); 
     } 
     //itsTheFinalCountdown(10000); 
    </script> 
</body> 

</html>