Skip to content

Instantly share code, notes, and snippets.

@ethertank
Created July 5, 2015 13:25
Show Gist options
  • Save ethertank/e84fb37312f6cbdc30e6 to your computer and use it in GitHub Desktop.
Save ethertank/e84fb37312f6cbdc30e6 to your computer and use it in GitHub Desktop.
Windows7 のコントロールパネルの「サウンド」に表示されている再生・録音デバイスの内、 一番上にあるものを一旦無効化し再度有効化する(再起動)スクリプト
/**********************************************************************************************
*
* Windows7 のコントロールパネルの「サウンド」に表示されている再生・録音デバイスの内、
* 一番上にあるものを一旦無効化し再度有効化する(再起動)スクリプト
*
* Auther: ethertank
* Usage: 当ファイルをPC内の任意の場所に配置し、右クリックメニューより編集を選択し、
* 文字コードを Unicode として保存。ショートカットを作成しておく。
* ショートカットをダブルクリックで実行。
**********************************************************************************************/
var wait = function(title){
do {
WScript.Sleep(100);
} while(!WshShell.AppActivate(title));
};
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.Run("control mmsys.cpl");
wait("サウンド");
WScript.Sleep(100);
//再生デバイス無効化
WshShell.SendKeys("{DOWN 1}%P");
WScript.Sleep(100);
WshShell.SendKeys("{DOWN}{TAB 3}{DOWN}{TAB 1}");
WScript.Sleep(100);
WshShell.SendKeys("{ENTER}");
WScript.Sleep(100);
//録音デバイス無効化
WshShell.SendKeys("^{TAB}");
WScript.Sleep(100);
WshShell.SendKeys("{DOWN 1}%P");
WScript.Sleep(100);
WshShell.SendKeys("{DOWN}{TAB 3}{DOWN}{TAB 1}");
WScript.Sleep(100);
WshShell.SendKeys("{ENTER}");
WScript.Sleep(100);
//録音デバイス有効化
WshShell.SendKeys("{DOWN 1}%P");
WScript.Sleep(100);
WshShell.SendKeys("{DOWN}{TAB 3}{UP}{TAB 1}");
WScript.Sleep(100);
WshShell.SendKeys("{ENTER}");
WScript.Sleep(100);
//再生デバイス有効化
WshShell.SendKeys("^+{TAB}");
WScript.Sleep(100);
WshShell.SendKeys("{DOWN 1}%P");
WScript.Sleep(100);
WshShell.SendKeys("{DOWN}{TAB 3}{UP}{TAB 1}");
WScript.Sleep(100);
WshShell.SendKeys("{ENTER}");
WScript.Sleep(100);
//「サウンド」を閉じる
WshShell.SendKeys("{ENTER}");
/**********************************************************************************************
*
* Windows7 のコントロールパネルの「サウンド」に表示されている再生・録音デバイスの内、
* 一番上にあるものを一旦無効化し再度有効化する(再起動)スクリプト(※一秒間隔実行テスト版)
*
* Auther: ethertank
* Usage: 当ファイルをPC内の任意の場所に配置し、右クリックメニューより編集を選択し、
* 文字コードを Unicode として保存。ショートカットを作成しておく。
* ショートカットをダブルクリックで実行。
**********************************************************************************************/
var wait = function(title){
do {
WScript.Sleep(100);
} while(!WshShell.AppActivate(title));
};
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.Run("control mmsys.cpl");
wait("サウンド");
WScript.Sleep(1000);
//再生デバイス無効化
WshShell.SendKeys("{DOWN 1}%P");
WScript.Sleep(1000);
WshShell.SendKeys("{DOWN}{TAB 3}{DOWN}{TAB 1}");
WScript.Sleep(1000);
WshShell.SendKeys("{ENTER}");
WScript.Sleep(1000);
//録音デバイス無効化
WshShell.SendKeys("^{TAB}");
WScript.Sleep(1000);
WshShell.SendKeys("{DOWN 1}%P");
WScript.Sleep(1000);
WshShell.SendKeys("{DOWN}{TAB 3}{DOWN}{TAB 1}");
WScript.Sleep(1000);
WshShell.SendKeys("{ENTER}");
WScript.Sleep(1000);
//録音デバイス有効化
WshShell.SendKeys("{DOWN 1}%P");
WScript.Sleep(1000);
WshShell.SendKeys("{DOWN}{TAB 3}{UP}{TAB 1}");
WScript.Sleep(1000);
WshShell.SendKeys("{ENTER}");
WScript.Sleep(1000);
//再生デバイス有効化
WshShell.SendKeys("^+{TAB}");
WScript.Sleep(1000);
WshShell.SendKeys("{DOWN 1}%P");
WScript.Sleep(1000);
WshShell.SendKeys("{DOWN}{TAB 3}{UP}{TAB 1}");
WScript.Sleep(1000);
WshShell.SendKeys("{ENTER}");
WScript.Sleep(1000);
//「サウンド」を閉じる
WshShell.SendKeys("{ENTER}");
/**************************************************************************************************************
*
* Windows でサウンドの再生デバイスを切り替えるためのスクリプト(バッチ処理)| すぐに忘れる脳みそのためのメモ:
* http://jutememo.blogspot.jp/2012/08/windows.html
*
* Windowsで音声形式を切り替えるためのスクリプト - standards for me :
* http://chryfopp.hatenablog.com/entry/2013/03/27/123749
*
* SendKeysメソッド - MSDN :
* https://msdn.microsoft.com/ja-jp/library/cc364423.aspx
*
*************************************************************************************************************/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment