それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

Windowsの環境変数を一覧する

Windowsの環境変数を使ってWSHを書くとき、環境変数が何処にあるか調べる。

WSHでバッチ処理するときにパスの解決など活用箇所は多い。

Windowsの環境変数を取得する。

WshShell = new ActiveXObject( "WScript.Shell" );
var env_names = ["USER", "SYSTEM", "VOLATILE", "PROCESS"];
for ( var i in env_names){
  var env = WshShell.Environment(env_names[i]);
  var e = new Enumerator(env);
  WScript.Echo( "-----------------------");
  WScript.Echo( env_names[i]);
  WScript.Echo( "-----------------------");
  for(;!e.atEnd();e.moveNext()){
    WScript.Echo( e.item() );
  }
}

実行例

Windowsで実行すると以下のような感じ。

-----------------------
USER
-----------------------
APR_ICONV_PATH=C:\Program Files\Subversion\iconv
Path=C:\Program Files\OpenSSH\bin;
TEMP=%USERPROFILE%\Local Settings\Temp
TMP=%USERPROFILE%\Local Settings\Temp
-----------------------
SYSTEM
-----------------------
APR_ICONV_PATH=C:\Program Files\Subversion\iconv
CLASSPATH=.;C:\Program Files\Java\jre1.6.0_07\lib\ext\QTJava.zip
COLINUX=C:\Program Files\coLinux
ComSpec=%SystemRoot%\system32\cmd.exe
FP_NO_HOST_CHECK=NO
NUMBER_OF_PROCESSORS=2
OS=Windows_NT
Path=%SystemRoot%\system32;%SystemRoot%;C:\Program Files\Subversion\bin;C:\Program Files\OpenSSH\bin;
PATHEXT=.COM;.EXE;.CMD;.VBS;.VBE;.JSE;.WSF;.WSH;.PSC1;
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 FaxxxxxxxxxxxxxxxxxineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=xxxx
QTJAVA=C:\Program Files\Java\jre1.6.0_07\lib\ext\QTJava.zip
TEMP=%SystemRoot%\TEMP
TMP=%SystemRoot%\TEMP
windir=%SystemRoot%
-----------------------
VOLATILE
-----------------------
LOGONSERVER=\\XXXX
CLIENTNAME=Console
SESSIONNAME=Console
APPDATA=C:\Documents and Settings\takuya_1st\Application Data
HOMEDRIVE=C:
HOMESHARE=
HOMEPATH=\Documents and Settings\takuya_1st
-----------------------
PROCESS
-----------------------
=::=::\
ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\takuya_1st\Application Data
APR_ICONV_PATH=C:\Program Files\Subversion\iconv
CLASSPATH=.;C:\Program Files\Java\jre1.6.0_07\lib\ext\QTJava.zip
CLIENTNAME=Console
CommonProgramFiles=C:\Program Files\Common Files
ComSpec=C:\WINDOWS\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\takuya_1st
NUMBER_OF_PROCESSORS=xxxx
PROCESSOR_ARCHITECTURE=xxxx
PROCESSOR_LEVEL=xxx
PROCESSOR_REVISION=xxxx
ProgramFiles=C:\Program Files
QTJAVA=C:\Program Files\Java\jre1.6.0_07\lib\ext\QTJava.zip
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\WINDOWS
TEMP=C:\DOCUME~1\takuya_1st\LOCALS~1\Temp
TMP=C:\DOCUME~1\takuya_1st\LOCALS~1\Temp
USERDOMAIN=xxxx
USERNAME=takuya_1st
USERPROFILE=C:\Documents and Settings\takuya_1st
windir=C:\WINDOWS