Skip to content

Instantly share code, notes, and snippets.

@the6th
Created October 24, 2018 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the6th/10edb4ca96656bb9e7764f8b49f69af5 to your computer and use it in GitHub Desktop.
Save the6th/10edb4ca96656bb9e7764f8b49f69af5 to your computer and use it in GitHub Desktop.
CPU 温度をbat で表示 管理者権限で実行/SJISで保存
@if(0)==(0) ECHO OFF
cscript.exe //nologo //E:JScript "%~f0" %*
@pause
GOTO :EOF
@end
// 温度を計測する間隔
var measure_interval_ms = 5000;
// 一つ前のタイミングの温度
var temperature_old = null;
// 温度を表示する関数
function show_temperature(){
// WMIをGetObject
var obj_service = GetObject("winmgmts:\\\\.\\root\\WMI");
// コンピュータ名「.」の前の\の個数を間違えると
// 0x80041021 のエラーになる。
// http://www.computerperformance.co.uk/Logon/code/code_80041021.htm
// WQLで温度取得
var record_set = obj_service.ExecQuery("SELECT * FROM MSAcpi_ThermalZoneTemperature", "WQL", 48);
var temperature_c;
// Enumeratorを使って,結果セットを1行ずつ読み取る
var e = new Enumerator( record_set );
for( ; ! e.atEnd(); e.moveNext() )
{
// 1件分のレコードを取得
var record = e.item();
// 温度
temperature_c = ( record.CurrentTemperature - 2732) / 10.0;
var s = "";
// 前回よりも温度が上がったら
if ( temperature_old < temperature_c ){
s = "    ・→→UP ";
}
// 前回よりも温度が下がったら
else if( temperature_old > temperature_c ){
s = "DOWN←←・    ";
}
else
{
s = "    ・    ";
}
s += "(" + temperature_c + "c)" + new Date();
WScript.Echo( s );
}
// 待つ
WScript.Sleep( measure_interval_ms );
// 今回の結果を保管
temperature_old = temperature_c;
}
// 無限ループ
while(true){
// 温度表示
show_temperature();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment