我如何使用批处理文件来改变我的电脑音量? [英] how can i change my computer volume using a batch file?

查看:1749
本文介绍了我如何使用批处理文件来改变我的电脑音量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个批次的报警,但我需要自动的方式把声音,所以我不必须。

目前的code报警(如果您有任何其他的改进随时提出他们)。

  @ECHO OFF
颜色0A
CLS
回声Ezlo报警系统
回声CURENT时间为:%时间%
集/ P输入=应在报警设置什么时候? (24小时)
:时间
CLS
回声EZY报警
回声CURENT时间为:%时间%
回声闹钟设置为输入%%
如果'%TIME%'=='%输入%GOTO报警
GOTO时间
:报警
ECHO起来!
启动D:\\用户\\网卡\\桌面\\ ezlo报警\\ alarmtone.mp3
回声preSS空间关闭
暂停> NUL


解决方案

当然,这是粗糙,但它的工作原理。重点code 0xAF执行是的虚拟键获取音量。这里有一点的JScript来发送关键code的50倍。

  VAR SHL =新的ActiveXObject(WScript.Shell);
对于(VAR I = 0; I< 50;我++){
    shl.SendKeys(String.fromChar code(0xAF执行));
}


您可以通过使用批处理+ JScript的混合格式纳入你的批处理脚本这一点。我做了一些其他的调整,以你的脚本为好,具有当前时间上退格,并再次输出,而不是清除屏幕上的每个循环中,使得时间比较数学比较让 HH的条目:毫米无需指定抛光这里和那里的秒厘秒,否则只是有点。

  @if(@a == @二)@end / *::批部分@ECHO OFF
SETLOCAL
CLS和放大器;&安培;颜色0A
::捕捉退格字符%BS%
FOR / F %%一个在('提示$的H&对于(1)不要REM %% B)并设置BS = %%一个
回声Ezlo报警系统
拨打:GETTIME现在
回声CURENT时间是:现在%%
集/ P输入=应在报警设置什么时候? (24小时)
回声;如果现在%%GEQ%输入%(设置明天= 1),否则设置明天=如果明天的定义(
    回声报警明天是设置%的输入%。
)其他回声闹钟设置为%的输入%。集/ P=该CURENT时间是:< NUL
:时间
拨打:GETTIME现在
集/ P=%现在%< NUL
如果现在%%GEQ%输入%(
    如果没有定义明天GOTO报警
)否则,如果定义设置明天的明天=
平-N 2 0.0.0.0> NUL
拨打:LEN%现在%LEN
对/ L %%我在(1,1,LEN%%)做设置/ P=%BS%< NUL
GOTO时间:报警
回声;
ECHO起来!
CSCRIPT / NOLOGO / E:JScript的%〜F0
启动D:\\用户\\网卡\\桌面\\ ezlo报警\\ alarmtone.mp3
回声preSS空间关闭
暂停> NUL
07色
退出/ B:GETTIME<&VARNAME GT;
设置gtvarnow =%的时间:0〜-3%
设置%〜1 =%gtvarnow:=%
GOTO:EOF:LEN<串GT; <&VARNAME GT;
设置LEN = 0
设置海峡=%〜1
:len_loop
如果定义STR(
    设置海峡=%STR:〜1%。
    集/ ALEN + = 1
    转到:len_loop
),否则设置%〜2 =%LEN%
GOTO:EOF
:: JScript的部分* /VAR SHL =新的ActiveXObject(WScript.Shell);
对于(VAR I = 0; I< 50;我++){
    shl.SendKeys(String.fromChar code(0xAF执行));
}


不幸的是,有编程没有简单的方法来检测该系统卷是否被静音。当然,还有一个关键的code切换静音,但没有简单的编程方法来检查是否需要被解雇或没有。如果您需要的脚本来强制系统不被静音,最简单的解决方法是使用第三方工具,如的的NirCmd 。请参见这个答案了解详情。

I am making a batch alarm but i need a way to turn the sound up automatically so I dont have to.

current code for alarm (if you have any other improvements feel free to suggest them).

@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

解决方案

Sure, this is crude, but it works. Key code 0xAF is a virtual key for volume up. Here's a bit of JScript to send that key code 50 times.

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


You can incorporate this into your batch script by using a batch + JScript hybrid format. I made a few other tweaks to your script as well, having the current time backspaced and reoutput instead of clearing the screen on every loop, making the time comparison a math comparison to allow entry of hh:mm without needing to specify seconds and centiseconds, and otherwise just a bit of polishing here and there.

@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));
}


Unfortunately, there's no easy way programmatically to detect whether the system volume is muted. Sure, there's a key code to toggle muting, but no easy programmatic way to check whether it needs to be fired or not. If you need your script to force the system not to be muted, the easiest solution is to use a 3rd party utility such as NirCmd. See this answer for details.

这篇关于我如何使用批处理文件来改变我的电脑音量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆