【问题标题】:how can i change my computer volume using a batch file?如何使用批处理文件更改我的计算机音量?
【发布时间】:2013-04-10 09:36:09
【问题描述】:

我正在制作一个批量警报,但我需要一种自动调高声音的方法,所以我不必这样做。

当前的警报代码(如果您有任何其他改进,请随时提出建议)。

@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

【问题讨论】:

    标签: batch-file time alarm


    【解决方案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 (@a==@b) @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));
    }
    

    很遗憾,没有简单的方法以编程方式检测系统音量是否已静音。当然,有一个切换静音的关键代码,但没有简单的编程方法来检查它是否需要被触发。如果您需要您的脚本来强制系统不静音,最简单的解决方案是使用第 3 方实用程序,例如 NirCmd。详情请见this answer

    【讨论】:

      【解决方案2】:

      http://gallery.technet.microsoft.com/scriptcenter/PowerShell-Set-PC-Volume-1737b160 您可以从批处理文件中调用此 exe 来控制音量。但我不确定你是否可以直接从批处理文件中完成

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-04-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-08
        • 1970-01-01
        • 2013-03-01
        • 2010-10-27
        相关资源
        最近更新 更多