2013-04-10 34 views
0

我正在做一個批量報警,但我需要一種方法來自動打開聲音,所以我不必。如何使用批處理文件更改我的計算機卷?

當前報警代碼(如果您有任何其他改進,請隨時提出建議)。

@ECHO OFF 
color 0a 
cls 
echo Ezlo alarm system 
echo The curent time is: %time% 
set /p INPUT=What time should the alarm be set for? (24hr) 
:time 
cls 
echo Ezy alarm 
echo The curent time is: %time% 
Echo Alarm is set for %input% 
if '%TIME%'=='%INPUT%' GOTO ALARM 
GOTO time 
:ALARM 
ECHO get up! 
start "D:\Users\nic\Desktop\ezlo alarm\alarmtone.mp3" 
echo press space to close 
PAUSE >nul 
+0

爲什麼這個問題標記爲[c]和[nul]? – alk 2013-04-10 09:48:46

+0

歡迎來到S.O.如果這是您第一次來這裏,請查看[此信息](http://meta.stackexchange.com/a/5235/187716)有關將答案標記爲已接受的信息。 – rojo 2013-04-10 13:19:38

回答

1

當然,這是粗糙的,但它的工作原理。密碼0xAF是一個virtual key音量增加。這裏有一些JScript發送密鑰代碼50次。

var shl = new ActiveXObject("WScript.Shell"); 
for (var i=0; i<50; i++) { 
    shl.SendKeys(String.fromCharCode(0xAF)); 
} 

您可以使用批處理+ JScript的混合格式整合到您的批處理腳本這一點。我還對你的腳本做了一些調整,使當前時間退後並重新輸出,而不是清除每個循環的屏幕,使時間比較成爲一個數學比較,允許輸入hh:mm而不需要指定秒和釐秒,否則只是在這裏和那裏拋光。

@if (@[email protected]) @end /* 

:: batch portion 

@ECHO OFF 
setlocal 
cls && color 0a 
:: capture backspace character to %BS% 
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a" 
echo Ezlo alarm system 
call :gettime now 
echo The curent time is: %now% 
set /p INPUT=What time should the alarm be set for? (24hr) 
echo; 

if "%now%" geq "%input%" (set tomorrow=1) else set tomorrow= 

if defined tomorrow (
    echo Alarm is set for %input% tomorrow. 
) else echo Alarm is set for %input%. 

set /p "=The curent time is: "<NUL 
:time 
call :gettime now 
set /p "=%now%"<NUL 
if "%now%" geq "%INPUT%" (
    if not defined tomorrow GOTO ALARM 
) else if defined tomorrow set tomorrow= 
ping -n 2 0.0.0.0 >NUL 
call :len %now% len 
for /l %%I in (1,1,%len%) do set /p "=%BS%"<NUL 
GOTO time 

:ALARM 
echo; 
ECHO get up! 
cscript /nologo /e:jscript "%~f0" 
start "" "D:\Users\nic\Desktop\ezlo alarm\alarmtone.mp3" 
echo press space to close 
PAUSE >nul 
color 07 
exit /b 

:gettime <varname> 
set "gtvarnow=%time:~0,-3%" 
set "%~1=%gtvarnow: =%" 
goto :EOF 

:len <string> <varname> 
set len=0 
set str=%~1 
:len_loop 
if defined str (
    set "str=%str:~1%" 
    set /a "len+=1" 
    goto :len_loop 
) else set "%~2=%len%" 
goto :EOF 


:: JScript portion */ 

var shl = new ActiveXObject("WScript.Shell"); 
for (var i=0; i<50; i++) { 
    shl.SendKeys(String.fromCharCode(0xAF)); 
} 

不幸的是,有編程沒有簡單的方法來檢測系統音量是否靜音。當然,有一個關鍵代碼來切換靜音,但沒有簡單的編程方法來檢查是否需要解除。如果您需要腳本強制系統不被靜音,最簡單的解決方案是使用第三方實用程序,如NirCmd。有關詳細信息,請參見this answer

相關問題