WshShell.ExpandEnvironmentStrings メソッド

本ページには広告が含まれています。

文字列内の環境変数を実際の値に置き換えるた文字列を取得できます。展開できるのはPROCESS環境領域に定義された環境変数のみです。

WshShell.Environment プロパティでは取得・設定ができます。

構文
WshShell.ExpandEnvironmentStrings( strString )
引数
strString 省略可
展開する環境変数の名前
戻り値

使い方

環境変数名のみ

環境変数名は%で囲んた文字列です。例えばAppDataの場合、%AppData%を指定し、展開されたパスを返します。

UWSC
DIM WshShell = CREATEOLEOBJ("WScript.Shell")
PRINT WshShell.ExpandEnvironmentStrings("%AppData%")
結果
プレーンテキスト
C:\Users\akita\AppData\Roaming

環境変数名を含む文字列

UWSCの設定が書かれているファイルがある%AppData%\UWSC\UWSC.INIのパスを展開します。

Windows XPではC:\Documents and Settings\uwsername\Application Data\UWSC\UWSC.INI、Vista以降ではC:\Users\username\AppData\Roaming\UWSC\UWSC.INIを返します。

UWSC
DIM WshShell = CREATEOLEOBJ("WScript.Shell")
path = WshShell.ExpandEnvironmentStrings("%AppData%\UWSC\UWSC.INI")
結果
プレーンテキスト
C:\Users\akita\AppData\Roaming\UWSC\UWSC.INI

存在しない環境変数名

存在しない環境変数は展開されず、そのまま出力されます。

UWSC
DIM WshShell = CREATEOLEOBJ("WScript.Shell")
PRINT WshShell.ExpandEnvironmentStrings("%User%\UWSC\UWSC.INI")
結果
プレーンテキスト
%User%UWSC\UWSC.INI

プロセス環境変数名を取得

以下はプロセス環境変数のみを取得するプログラムです。

UWSC
DIM WshShell = CREATEOLEOBJ("WScript.Shell")

FOR item IN WshShell.Environment("Process")
	PRINT TOKEN("=", item)
NEXT
結果
プレーンテキスト

ALLUSERSPROFILE
APPDATA
CommonProgramFiles
CommonProgramFiles(x86)
CommonProgramW6432
COMPUTERNAME
ComSpec
DriverData
FPS_BROWSER_APP_PROFILE_STRING
FPS_BROWSER_USER_PROFILE_STRING
FP_NO_HOST_CHECK
FREI0R_PATH
HOMEDRIVE
HOMEPATH
JD2_HOME
LOCALAPPDATA
LOGONSERVER
NUMBER_OF_PROCESSORS
OneDrive
OS
Path
PATHEXT
PROCESSOR_ARCHITECTURE
PROCESSOR_ARCHITEW6432
PROCESSOR_IDENTIFIER
PROCESSOR_LEVEL
PROCESSOR_REVISION
ProgramData
ProgramFiles
ProgramFiles(x86)
ProgramW6432
PSModulePath
PUBLIC
SCITE_USERHOME
SESSIONNAME
SystemDrive
SystemRoot
TEMP
TMP
UD_INSTALL_DIR
USERDOMAIN
USERDOMAIN_ROAMINGPROFILE
USERNAME
USERPROFILE
windir
windows_tracing_flags
windows_tracing_logfile

プログラム実行例

UWSC.INIよりUWSC本体のウィンドウの幅と高さを取得

UWSC起動時のウィンドウの座標を幅,高さの形式で取得します。

MainSizeキーは初期では定義されていないので、値を取得できないこともあります。

UWSC
DIM WshShell = CREATEOLEOBJ("WScript.Shell")
DIM path = WshShell.ExpandEnvironmentStrings("%AppData%\UWSC\UWSC.INI")

PRINT READINI("SET", "MainSize", path)

//////////////////////////////////////////////////
// 【引数】
//   section : セクション 
//   key : キー(Delete関数は省略可) 
//   value : 値 
//   path : INIファイルのパス 
//   default : セクションとキーが存在しなかった場合に返す値 
// 【戻り値】
//   
//////////////////////////////////////////////////
MODULE INI
	DEF_DLL GetPrivateProfileStringW(wstring,wstring,wstring,var pwchar,dword,wstring):dword:kernel32
	DEF_DLL WritePrivateProfileStringW(wstring,wstring,wstring,wstring):bool:kernel32
	FUNCTION Read(section = NULL, key = NULL, path = NULL, default = EMPTY)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		DIM n = 1024
		DIM buffer = FORMAT(CHR(0), n)
		IFB GetPrivateProfileStringW(section, key, default, buffer, n, path) = 0 THEN
			RESULT = default
		ELSE
			RESULT = SLICE(SPLIT(buffer, CHR(0), TRUE))
			IF section <> NULL AND key <> NULL THEN RESULT = RESULT[0]
		ENDIF
	FEND
	FUNCTION Write(section, key, value, path = NULL)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		RESULT = WritePrivateProfileStringW(section, key, value, path)
	FEND
	PROCEDURE Delete(section, key = NULL, path = NULL)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		PRINT WritePrivateProfileStringW(section, key, NULL, path)
	FEND
	FUNCTION escape(value)
		DIM esc = ";#=:"
		FOR i = 1 TO LENGTH(esc)
			DIM s = COPY(esc, i, 1)
			value = REPLACE(value, s, "\" + s)
		NEXT
		RESULT = value
	FEND
	FUNCTION unescape(value)
		DIM esc = ";#=:"
		FOR i = 1 TO LENGTH(esc)
			DIM s = COPY(esc, i, 1)
			value = REPLACE(value, "\" + s, s)
		NEXT
		RESULT = value
	FEND
ENDMODULE
結果
プレーンテキスト
220,61
解説

ユーザー名を取得

[createLink url="/com/wshshell/"]を使い環境変数の値を取得します。

以下は%USERNAME%の値(ユーザー名)を取得しています。

UWSC
DIM WshShell = CREATEOLEOBJ("WScript.Shell")
PRINT WshShell.ExpandEnvironmentStrings("%USERNAME%")
結果
プレーンテキスト
akita
使用関数
解説

UWSC.INIよりUWSCウィンドウの位置を取得

UWSC起動時のウィンドウの位置をx座標,y座標の形式で取得します。

UWSC
DIM WshShell = CREATEOLEOBJ("WScript.Shell")
PRINT READINI("SET", "Position", WshShell.ExpandEnvironmentStrings("%AppData%\UWSC\UWSC.INI"))

//////////////////////////////////////////////////
// 【引数】
//   section : セクション 
//   key : キー(Delete関数は省略可) 
//   value : 値 
//   path : INIファイルのパス 
//   default : セクションとキーが存在しなかった場合に返す値 
// 【戻り値】
//   
//////////////////////////////////////////////////
MODULE INI
	DEF_DLL GetPrivateProfileStringW(wstring,wstring,wstring,var pwchar,dword,wstring):dword:kernel32
	DEF_DLL WritePrivateProfileStringW(wstring,wstring,wstring,wstring):bool:kernel32
	FUNCTION Read(section = NULL, key = NULL, path = NULL, default = EMPTY)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		DIM n = 1024
		DIM buffer = FORMAT(CHR(0), n)
		IFB GetPrivateProfileStringW(section, key, default, buffer, n, path) = 0 THEN
			RESULT = default
		ELSE
			RESULT = SLICE(SPLIT(buffer, CHR(0), TRUE))
			IF section <> NULL AND key <> NULL THEN RESULT = RESULT[0]
		ENDIF
	FEND
	FUNCTION Write(section, key, value, path = NULL)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		RESULT = WritePrivateProfileStringW(section, key, value, path)
	FEND
	PROCEDURE Delete(section, key = NULL, path = NULL)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		PRINT WritePrivateProfileStringW(section, key, NULL, path)
	FEND
	FUNCTION escape(value)
		DIM esc = ";#=:"
		FOR i = 1 TO LENGTH(esc)
			DIM s = COPY(esc, i, 1)
			value = REPLACE(value, s, "\" + s)
		NEXT
		RESULT = value
	FEND
	FUNCTION unescape(value)
		DIM esc = ";#=:"
		FOR i = 1 TO LENGTH(esc)
			DIM s = COPY(esc, i, 1)
			value = REPLACE(value, "\" + s, s)
		NEXT
		RESULT = value
	FEND
ENDMODULE
結果
プレーンテキスト
549,588
解説

UWSC.INIよりUWSCを再生するホットキーを取得

Roamingフォルダ(C:\Users\username\AppData\Roaming\)のUWSCフォルダにあるUWSC.INIを読み込み、UWSCを停止するホットキーを取得します。

UWSC
DIM modifers[] = "CTRL", "WIN", "ALT", "SHIFT+CTRL", "SHIFT+ALT", "CTRL+ALT"
DIM keys[] = "SPACE", "F1", "F2", "F3", "F4", "F9", "F10", "F11", "F12", "↑", _
				"↓", "→", "←", "Q", "W", "E", "R", "A", "S", "D", _
				"F", "End", "Home", "F5", "F6", "F7", "F8", "T", "Y", "U", _
				"I", "O", "P", "G", "H", "J", "K", "L", "Z", "X", _
				"C", "V", "B", "N", "M", "1", "2", "3", "4", "5", _
				"6", "7", "8", "9"

DIM WshShell = CREATEOLEOBJ("WScript.Shell")
DIM str = READINI("SET", "PlayHotKey", WshShell.ExpandEnvironmentStrings("%AppData%\UWSC\UWSC.INI"))
DIM nums = SPLIT(str, ",")

PRINT modifers[nums[1]] + "+" + keys[nums[0]]

//////////////////////////////////////////////////
// 【引数】
//   section : セクション 
//   key : キー(Delete関数は省略可) 
//   value : 値 
//   path : INIファイルのパス 
//   default : セクションとキーが存在しなかった場合に返す値 
// 【戻り値】
//   
//////////////////////////////////////////////////
MODULE INI
	DEF_DLL GetPrivateProfileStringW(wstring,wstring,wstring,var pwchar,dword,wstring):dword:kernel32
	DEF_DLL WritePrivateProfileStringW(wstring,wstring,wstring,wstring):bool:kernel32
	FUNCTION Read(section = NULL, key = NULL, path = NULL, default = EMPTY)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		DIM n = 1024
		DIM buffer = FORMAT(CHR(0), n)
		IFB GetPrivateProfileStringW(section, key, default, buffer, n, path) = 0 THEN
			RESULT = default
		ELSE
			RESULT = SLICE(SPLIT(buffer, CHR(0), TRUE))
			IF section <> NULL AND key <> NULL THEN RESULT = RESULT[0]
		ENDIF
	FEND
	FUNCTION Write(section, key, value, path = NULL)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		RESULT = WritePrivateProfileStringW(section, key, value, path)
	FEND
	PROCEDURE Delete(section, key = NULL, path = NULL)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		PRINT WritePrivateProfileStringW(section, key, NULL, path)
	FEND
	FUNCTION escape(value)
		DIM esc = ";#=:"
		FOR i = 1 TO LENGTH(esc)
			DIM s = COPY(esc, i, 1)
			value = REPLACE(value, s, "\" + s)
		NEXT
		RESULT = value
	FEND
	FUNCTION unescape(value)
		DIM esc = ";#=:"
		FOR i = 1 TO LENGTH(esc)
			DIM s = COPY(esc, i, 1)
			value = REPLACE(value, "\" + s, s)
		NEXT
		RESULT = value
	FEND
ENDMODULE
[syntaxHighlight language="INI" title="UWSC.INI"][SET] Position=7,81 PlayHotKey=1,2 StopHotKey=2,2 RecHotKey=3,2 TrayHotKey=14,5 LunchMenuHotKey=14,0 MouseOrg=0 NotActive=0 StayOnTop=0 LogLines=2000 DefaultFont=, TaskTrayStart=1[/syntaxHighlight]
結果
プレーンテキスト
ALT+F1
使用関数
解説

UWSC.INIよりUWSCを停止するホットキーを取得

UWSC
DIM modifers[] = "CTRL", "WIN", "ALT", "SHIFT+CTRL", "SHIFT+ALT", "CTRL+ALT"
DIM keys[] = "SPACE", "F1", "F2", "F3", "F4", "F9", "F10", "F11", "F12", "↑", _
				"↓", "→", "←", "Q", "W", "E", "R", "A", "S", "D", _
				"F", "End", "Home", "F5", "F6", "F7", "F8", "T", "Y", "U", _
				"I", "O", "P", "G", "H", "J", "K", "L", "Z", "X", _
				"C", "V", "B", "N", "M", "1", "2", "3", "4", "5", _
				"6", "7", "8", "9"

DIM WshShell = CREATEOLEOBJ("WScript.Shell")
DIM str = READINI("SET", "StopHotKey", WshShell.ExpandEnvironmentStrings("%AppData%\UWSC\UWSC.INI"))
DIM nums = SPLIT(str, ",")

PRINT modifers[nums[1]] + "+" + keys[nums[0]]

//////////////////////////////////////////////////
// 【引数】
//   section : セクション 
//   key : キー(Delete関数は省略可) 
//   value : 値 
//   path : INIファイルのパス 
//   default : セクションとキーが存在しなかった場合に返す値 
// 【戻り値】
//   
//////////////////////////////////////////////////
MODULE INI
	DEF_DLL GetPrivateProfileStringW(wstring,wstring,wstring,var pwchar,dword,wstring):dword:kernel32
	DEF_DLL WritePrivateProfileStringW(wstring,wstring,wstring,wstring):bool:kernel32
	FUNCTION Read(section = NULL, key = NULL, path = NULL, default = EMPTY)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		DIM n = 1024
		DIM buffer = FORMAT(CHR(0), n)
		IFB GetPrivateProfileStringW(section, key, default, buffer, n, path) = 0 THEN
			RESULT = default
		ELSE
			RESULT = SLICE(SPLIT(buffer, CHR(0), TRUE))
			IF section <> NULL AND key <> NULL THEN RESULT = RESULT[0]
		ENDIF
	FEND
	FUNCTION Write(section, key, value, path = NULL)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		RESULT = WritePrivateProfileStringW(section, key, value, path)
	FEND
	PROCEDURE Delete(section, key = NULL, path = NULL)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		PRINT WritePrivateProfileStringW(section, key, NULL, path)
	FEND
	FUNCTION escape(value)
		DIM esc = ";#=:"
		FOR i = 1 TO LENGTH(esc)
			DIM s = COPY(esc, i, 1)
			value = REPLACE(value, s, "\" + s)
		NEXT
		RESULT = value
	FEND
	FUNCTION unescape(value)
		DIM esc = ";#=:"
		FOR i = 1 TO LENGTH(esc)
			DIM s = COPY(esc, i, 1)
			value = REPLACE(value, "\" + s, s)
		NEXT
		RESULT = value
	FEND
ENDMODULE
[syntaxHighlight language="INI" title="UWSC.INI"][SET] Position=7,81 PlayHotKey=1,2 StopHotKey=2,2 RecHotKey=3,2 TrayHotKey=14,5 LunchMenuHotKey=14,0 MouseOrg=0 NotActive=0 StayOnTop=0 LogLines=2000 DefaultFont=, TaskTrayStart=1[/syntaxHighlight]
結果
プレーンテキスト
ALT+F2
解説

UWSC.INIよりUWSCを記録するホットキーを取得

Roamingフォルダ(C:\Users\username\AppData\Roaming\)のUWSCフォルダにあるUWSC.INIを読み込み、UWSCを記録するホットキーを取得します。

UWSC
DIM modifers[] = "CTRL", "WIN", "ALT", "SHIFT+CTRL", "SHIFT+ALT", "CTRL+ALT"
DIM keys[] = "SPACE", "F1", "F2", "F3", "F4", "F9", "F10", "F11", "F12", "↑", _
				"↓", "→", "←", "Q", "W", "E", "R", "A", "S", "D", _
				"F", "End", "Home", "F5", "F6", "F7", "F8", "T", "Y", "U", _
				"I", "O", "P", "G", "H", "J", "K", "L", "Z", "X", _
				"C", "V", "B", "N", "M", "1", "2", "3", "4", "5", _
				"6", "7", "8", "9"

DIM WshShell = CREATEOLEOBJ("WScript.Shell")
DIM str = READINI("SET", "RecHotKey", WshShell.ExpandEnvironmentStrings("%AppData%\UWSC\UWSC.INI"))
DIM nums = SPLIT(str, ",")

PRINT modifers[nums[1]] + "+" + keys[nums[0]]

//////////////////////////////////////////////////
// 【引数】
//   section : セクション 
//   key : キー(Delete関数は省略可) 
//   value : 値 
//   path : INIファイルのパス 
//   default : セクションとキーが存在しなかった場合に返す値 
// 【戻り値】
//   
//////////////////////////////////////////////////
MODULE INI
	DEF_DLL GetPrivateProfileStringW(wstring,wstring,wstring,var pwchar,dword,wstring):dword:kernel32
	DEF_DLL WritePrivateProfileStringW(wstring,wstring,wstring,wstring):bool:kernel32
	FUNCTION Read(section = NULL, key = NULL, path = NULL, default = EMPTY)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		DIM n = 1024
		DIM buffer = FORMAT(CHR(0), n)
		IFB GetPrivateProfileStringW(section, key, default, buffer, n, path) = 0 THEN
			RESULT = default
		ELSE
			RESULT = SLICE(SPLIT(buffer, CHR(0), TRUE))
			IF section <> NULL AND key <> NULL THEN RESULT = RESULT[0]
		ENDIF
	FEND
	FUNCTION Write(section, key, value, path = NULL)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		RESULT = WritePrivateProfileStringW(section, key, value, path)
	FEND
	PROCEDURE Delete(section, key = NULL, path = NULL)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		PRINT WritePrivateProfileStringW(section, key, NULL, path)
	FEND
	FUNCTION escape(value)
		DIM esc = ";#=:"
		FOR i = 1 TO LENGTH(esc)
			DIM s = COPY(esc, i, 1)
			value = REPLACE(value, s, "\" + s)
		NEXT
		RESULT = value
	FEND
	FUNCTION unescape(value)
		DIM esc = ";#=:"
		FOR i = 1 TO LENGTH(esc)
			DIM s = COPY(esc, i, 1)
			value = REPLACE(value, "\" + s, s)
		NEXT
		RESULT = value
	FEND
ENDMODULE

UWSCを記録するホットキーはSETセクションのRecHotKeyで取得できます。

[syntaxHighlight language="INI" title="UWSC.INI"][SET] Position=7,81 PlayHotKey=1,2 StopHotKey=2,2 RecHotKey=3,2 TrayHotKey=14,5 LunchMenuHotKey=14,0 MouseOrg=0 NotActive=0 StayOnTop=0 LogLines=2000 DefaultFont=, TaskTrayStart=1[/syntaxHighlight]
結果
プレーンテキスト
ALT+F3
解説

UWSC.INIよりUWSCをトレイに格納するホットキーを取得

Roamingフォルダ(C:\Users\username\AppData\Roaming\)のUWSCフォルダにあるUWSC.INIを読み込み、トレイに格納するホットキーを取得します。

UWSC
DIM modifers[] = "CTRL", "WIN", "ALT", "SHIFT+CTRL", "SHIFT+ALT", "CTRL+ALT"
DIM keys[] = "SPACE", "F1", "F2", "F3", "F4", "F9", "F10", "F11", "F12", "↑", _
				"↓", "→", "←", "Q", "W", "E", "R", "A", "S", "D", _
				"F", "End", "Home", "F5", "F6", "F7", "F8", "T", "Y", "U", _
				"I", "O", "P", "G", "H", "J", "K", "L", "Z", "X", _
				"C", "V", "B", "N", "M", "1", "2", "3", "4", "5", _
				"6", "7", "8", "9"

DIM WshShell = CREATEOLEOBJ("WScript.Shell")
DIM str = READINI("SET", "TrayHotKey", WshShell.ExpandEnvironmentStrings("%AppData%\UWSC\UWSC.INI"))
DIM nums = SPLIT(str, ",")

PRINT modifers[nums[1]] + "+" + keys[nums[0]]

//////////////////////////////////////////////////
// 【引数】
//   section : セクション 
//   key : キー(Delete関数は省略可) 
//   value : 値 
//   path : INIファイルのパス 
//   default : セクションとキーが存在しなかった場合に返す値 
// 【戻り値】
//   
//////////////////////////////////////////////////
MODULE INI
	DEF_DLL GetPrivateProfileStringW(wstring,wstring,wstring,var pwchar,dword,wstring):dword:kernel32
	DEF_DLL WritePrivateProfileStringW(wstring,wstring,wstring,wstring):bool:kernel32
	FUNCTION Read(section = NULL, key = NULL, path = NULL, default = EMPTY)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		DIM n = 1024
		DIM buffer = FORMAT(CHR(0), n)
		IFB GetPrivateProfileStringW(section, key, default, buffer, n, path) = 0 THEN
			RESULT = default
		ELSE
			RESULT = SLICE(SPLIT(buffer, CHR(0), TRUE))
			IF section <> NULL AND key <> NULL THEN RESULT = RESULT[0]
		ENDIF
	FEND
	FUNCTION Write(section, key, value, path = NULL)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		RESULT = WritePrivateProfileStringW(section, key, value, path)
	FEND
	PROCEDURE Delete(section, key = NULL, path = NULL)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		PRINT WritePrivateProfileStringW(section, key, NULL, path)
	FEND
	FUNCTION escape(value)
		DIM esc = ";#=:"
		FOR i = 1 TO LENGTH(esc)
			DIM s = COPY(esc, i, 1)
			value = REPLACE(value, s, "\" + s)
		NEXT
		RESULT = value
	FEND
	FUNCTION unescape(value)
		DIM esc = ";#=:"
		FOR i = 1 TO LENGTH(esc)
			DIM s = COPY(esc, i, 1)
			value = REPLACE(value, "\" + s, s)
		NEXT
		RESULT = value
	FEND
ENDMODULE

トレイに格納するホットキーはSETセクションのTrayHotKeyの値で、組み合わせるキー,修飾子キーの形式です。

[syntaxHighlight language="INI" title="UWSC.INI"][SET] Position=7,81 PlayHotKey=1,2 StopHotKey=2,2 RecHotKey=3,2 TrayHotKey=14,5 LunchMenuHotKey=14,0 MouseOrg=0 NotActive=0 StayOnTop=0 LogLines=2000 DefaultFont=, TaskTrayStart=1[/syntaxHighlight]
結果
プレーンテキスト
CTRL+ALT+W
解説

UWSC.INIよりUWSCをランチメニューを表示するホットキーを取得

Roamingフォルダ(C:\Users\username\AppData\Roaming\)のUWSCフォルダにあるUWSC.INIを読み込み、ランチメニューのホットキーを取得します。

UWSC
DIM modifers[] = "CTRL", "WIN", "ALT", "SHIFT+CTRL", "SHIFT+ALT", "CTRL+ALT"
DIM keys[] = "SPACE", "F1", "F2", "F3", "F4", "F9", "F10", "F11", "F12", "↑", _
				"↓", "→", "←", "Q", "W", "E", "R", "A", "S", "D", _
				"F", "End", "Home", "F5", "F6", "F7", "F8", "T", "Y", "U", _
				"I", "O", "P", "G", "H", "J", "K", "L", "Z", "X", _
				"C", "V", "B", "N", "M", "1", "2", "3", "4", "5", _
				"6", "7", "8", "9"

DIM WshShell = CREATEOLEOBJ("WScript.Shell")
DIM str = READINI("SET", "LunchMenuHotKey", WshShell.ExpandEnvironmentStrings("%AppData%\UWSC\UWSC.INI"))
DIM nums = SPLIT(str, ",")

PRINT modifers[nums[1]] + "+" + keys[nums[0]]

//////////////////////////////////////////////////
// 【引数】
//   section : セクション 
//   key : キー(Delete関数は省略可) 
//   value : 値 
//   path : INIファイルのパス 
//   default : セクションとキーが存在しなかった場合に返す値 
// 【戻り値】
//   
//////////////////////////////////////////////////
MODULE INI
	DEF_DLL GetPrivateProfileStringW(wstring,wstring,wstring,var pwchar,dword,wstring):dword:kernel32
	DEF_DLL WritePrivateProfileStringW(wstring,wstring,wstring,wstring):bool:kernel32
	FUNCTION Read(section = NULL, key = NULL, path = NULL, default = EMPTY)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		DIM n = 1024
		DIM buffer = FORMAT(CHR(0), n)
		IFB GetPrivateProfileStringW(section, key, default, buffer, n, path) = 0 THEN
			RESULT = default
		ELSE
			RESULT = SLICE(SPLIT(buffer, CHR(0), TRUE))
			IF section <> NULL AND key <> NULL THEN RESULT = RESULT[0]
		ENDIF
	FEND
	FUNCTION Write(section, key, value, path = NULL)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		RESULT = WritePrivateProfileStringW(section, key, value, path)
	FEND
	PROCEDURE Delete(section, key = NULL, path = NULL)
		DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
		IFB path = NULL THEN
			path = FSO.GetAbsolutePathName(FSO.GetBaseName(GET_UWSC_NAME) + ".INI")
		ELSE
			path = FSO.GetAbsolutePathName(path)
		ENDIF
		PRINT WritePrivateProfileStringW(section, key, NULL, path)
	FEND
	FUNCTION escape(value)
		DIM esc = ";#=:"
		FOR i = 1 TO LENGTH(esc)
			DIM s = COPY(esc, i, 1)
			value = REPLACE(value, s, "\" + s)
		NEXT
		RESULT = value
	FEND
	FUNCTION unescape(value)
		DIM esc = ";#=:"
		FOR i = 1 TO LENGTH(esc)
			DIM s = COPY(esc, i, 1)
			value = REPLACE(value, "\" + s, s)
		NEXT
		RESULT = value
	FEND
ENDMODULE

ランチメニューのホットキーはSETセクションのLunchMenuHotKeyキーの値で、組み合わせるキー,修飾子キーの形式です。

[syntaxHighlight language="INI" title="UWSC.INI"][SET] Position=7,81 PlayHotKey=1,2 StopHotKey=2,2 RecHotKey=3,2 TrayHotKey=14,5 LunchMenuHotKey=14,0 MouseOrg=0 NotActive=0 StayOnTop=0 LogLines=2000 DefaultFont=, TaskTrayStart=1[/syntaxHighlight]
結果
プレーンテキスト
Ctrl+W
解説