READINIリードイニ関数

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

INIファイルの値を読み込みます。INIファイルが存在しない、セクション・キーが設定されていない場合空文字("")を返します。読み込むINIファイルはUWSCファイルと同じディレクトリに置きます。INIファイルに書き込むにはWRITEINI関数を使います。

構文
  1. UString = READINI( セクション, キー, INIファイル名 )
引数
セクション (String)必須
セクション名
キー (String)必須
キー名
INIファイル名 (String = スクリプト名.INI)省略可
デフォルト(省略時)では、カレントディレクトリにスクリプト名.INI
戻り値
取得した値

INIファイル(初期化ファイル)

INIファイルは設定に関する情報を保存するためのファイルです。

[ ]内にセクション名、=の左にキー名、右に値を記述します。

INI
[section1]
key1=value1      ;コメント
key2=value2
key3=value3
[section2]
key1=value1
key2=value2

INIファイルにパスワードを保存するときの注意点

INIファイルにIDやパスワードの個人情報を平文で保存するのは、ファイルが盗まれたら簡単に不正アクセスされてしまうため危険です。

そこで万が一ファイルが盗まれた際の不正アクセスを防ぐために、個人情報を暗号化することをおすすめします。

Cipher (自作関数)を作成してありますので、ぜひご活用下さい。

使い方

パスがC:\Users\username\AppData\Roaming\UWSC\UWSC.INIのセクション名がSET、キー名がPositionの値を取得します。

UWSC
DIM path = "C:\Users\" + TRIM(DOSCMD("echo %username%")) + "\AppData\Roaming\UWSC\UWSC.INI"

PRINT READINI("SET", "Position", path)
UWSC.INI
[SET]
Position=411,338
PlayHotKey=1,2
StopHotKey=2,2
RecHotKey=3,2
TrayHotKey=14,5
LunchMenuHotKey=19,2
MouseOrg=0
NotActive=0
StayOnTop=0
LogLines=2000
DefaultFont=,
TaskTrayStart=1
RecLevel=1
Cp2Clipboard=1
NotExtraMovRec=0
結果
プレーンテキスト
411,338

存在しないキー名を指定した(LogLinesと書くべきところにLogLineと書いた)場合、空文字("")を返します。

UWSC
DIM path = "C:\Users\" + TRIM(DOSCMD("echo %username%")) + "\AppData\Roaming\UWSC\UWSC.INI"

PRINT READINI("SET", "LogLine", path)
UWSC.INI
[SET]
Position=411,338
PlayHotKey=1,2
StopHotKey=2,2
RecHotKey=3,2
TrayHotKey=14,5
LunchMenuHotKey=19,2
MouseOrg=0
NotActive=0
StayOnTop=0
LogLines=2000
DefaultFont=,
TaskTrayStart=1
RecLevel=1
Cp2Clipboard=1
NotExtraMovRec=0
結果
プレーンテキスト

同じセクション名・キー名が複数ある場合、一番上にあるものが取得されます。

INI
[SECTION]
data=123
data=456
data=789
UWSC
PRINT READINI("SECTION", "data")
結果
プレーンテキスト
123

キー名は初めてイコール(=)がくる位置までです。WRITEINI関数で以下のようにキー名をdata=123、値を456として書き込んでも、READINI関数で読み込むときはdataがキー名、123=456が値になります。

INI
[SECTION]
data=123=456
UWSC
WRITEINI("SECTION", "data=123", "456")
PRINT READINI("SECTION", "data")
結果
プレーンテキスト
123=456

キー名=値のあとにコメントがあると、コメントも取得されるので注意してください。

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
[LUNCHMENU]
Position=0,0
T1=サンプル
S1=.\sample\サンプル.UWS
[SCHEDULE]
MaxNumber=40
UWSC
PRINT READINI("SET", "Position", "UWSC.INI")
結果
プレーンテキスト
7,81				; 位置

プログラム実行例

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
使用関数
解説

UWSCの実行日時をINIファイルに書き込み・読み込み

UWSC
DIM section = "設定"
DIM key = "datetime"
DIM filename = "設定.INI"

DIM datetime = READINI(section , key, filename)
WRITEINI(section, key, text(now(), "yyyy/mm/dd hh:nn:ss", filename))

PRINT "■前回の実行日時"
PRINT datetime

//////////////////////////////////////////////////
// 【引数】
//   interval : 加算する時間間隔を表す文字列式(yyyy:年、m:月、d:日、ww:週、h:時、n:分、s:秒) 
//   num : dateに加算する値。未来は正、過去は負で指定 
//   date : 時間間隔を加算する日付 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION dateAdd(interval, num, date)
	DIM year, month, day, d
	GETTIME(0, date)
	DIM time = G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2
	SELECT interval
		CASE "yyyy"
			d = (G_TIME_YY + num) + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
			IF time <> "00:00:00" THEN d = d + " " + time
		CASE "m"
			IFB num > 0 THEN
				year = G_TIME_YY + INT((G_TIME_MM + num) / 12)
				month = REPLACE(FORMAT(((G_TIME_MM + num) MOD 12), 2), " ", "0")
			ELSE
				year = G_TIME_YY + CEIL((G_TIME_MM + num) / 12 - 1)
				month = REPLACE(FORMAT(G_TIME_MM - (ABS(num) MOD 12), 2), " ", "0")
			ENDIF
			IF month = "00" THEN month = 12
			day = G_TIME_DD2
			d = "" + year + month + day
			IFB !isDate(d) THEN
				d = year + "/" + month + "/" + "01"
				d = getEndOfMonth(d)
			ELSE
				d = year + "/" + month + "/" + day
			ENDIF
			IF time <> "00:00:00" THEN d = d + " " + time
		CASE "d"
			t = GETTIME(num, date)
			d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
		CASE "ww"
			t = GETTIME(num * 7, date)
			d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
		CASE "h"
			t = GETTIME(num / 24, date)
			d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
		CASE "n"
			t = GETTIME(num / 1440, date)
			d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
		CASE "s"
			t = GETTIME(num / 86400, date)
			d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
	SELEND
	RESULT = d
FEND

//////////////////////////////////////////////////
// 【引数】
//   interval : 時間単位(yyyy︰年、q:四半期、m︰月、d︰日、w:週日、ww:週、h:時、n:分、s:秒) 
//   date1 : 日時1 
//   date2 : 日時2 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION dateDiff(interval, date1, date2)
	DIM y1, y2, m1, m2, d1, d2, d
	SELECT interval
		CASE "yyyy"
			GETTIME(0, date1)
			y1 = G_TIME_YY
			GETTIME(0, date2)
			y2 = G_TIME_YY
			d = y2 - y1
		CASE "q"
			GETTIME(0, date1)
			y1 = G_TIME_YY
			m1 = G_TIME_MM
			GETTIME(0, date2)
			y2 = G_TIME_YY
			m2 = G_TIME_MM
			d = y2 * 4 + CEIL(m2/3) - (y1 * 4 + CEIL(m1/3))
		CASE "m"
			GETTIME(0, date1)
			y1 = G_TIME_YY
			m1 = G_TIME_MM
			GETTIME(0, date2)
			y2 = G_TIME_YY
			m2 = G_TIME_MM
			d = (y2 - y1) * 12 + m2 - m1
		CASE "d"
			d1 = GETTIME(0, date1)
			d2 = GETTIME(0, date2)
			d = (d2 - d1) / 86400
		CASE "w"
			d = INT(dateDiff("d", date1, date2) / 7)
		CASE "ww"
			date1 = dateAdd("d", -1 * getWeekday(date1), date1)
			d = INT(dateDiff("d", date1, date2) / 7)
		CASE "h"
			d = dateDiff("d", date1, date2) * 24
		CASE "n"
			d = dateDiff("d", date1, date2) * 1440
		CASE "s"
			d = dateDiff("d", date1, date2) * 86400
	SELEND
	RESULT = d
FEND

//////////////////////////////////////////////////
// 【引数】
//   array : 最大公約数を求める数値を格納した配列 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION GCD(array[])
	DIM c = LENGTH(array)
	DIM rem = array[c-1] MOD array[c-2]
	IFB rem = 0 THEN
		IFB LENGTH(array) = 2 THEN
			RESULT = array[c-2]
			EXIT
		ENDIF
		RESIZE(array, c-2)
		RESULT = GCD(array)
		EXIT
	ENDIF
	array[c-1] = array[c-2]
	array[c-2] = rem
	RESULT = GCD(array)
FEND

//////////////////////////////////////////////////
// 【引数】
//   date : 日付(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”) 
//   m : 第一引数の指定日からプラスマイナスm月とする 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION getEndOfMonth(date, m = 0)
	date = dateAdd("m", m + 1, date)
	GETTIME(0, date)
	GETTIME(-G_TIME_DD, date)
	RESULT = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
FEND

//////////////////////////////////////////////////
// 【引数】
//   date : (”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”) 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION getWeekday(date)
	GETTIME(0, date)
	RESULT = G_TIME_WW
FEND

//////////////////////////////////////////////////
// 【引数】
//   数値 : GETTIMEで取得した曜日の番号(G_TIME_WW=0:日曜….6:土曜) 
//   フォーマット : 以下のアルファベットは数値で指定した対応する曜日に置き換えられます。(aaa : 日〜土、aaaa : 日曜日〜土曜日、ddd : Sun〜Sat、dddd : Sunday〜Saturday) 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION getWeekdayName(num, format = "aaa")
	DIM re = CREATEOLEOBJ("VBScript.RegExp")
	DIM aaa[] = "日", "月", "火", "水", "木", "金", "土";
	DIM aaaa[] = "日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日";
	DIM ddd[] = "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat";
	DIM dddd[] = "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday";
	match = reExecute(format, "(a|d)+")
	type = match.Item(0).Value
	RESULT = reReplace(format, EVAL(type + "[" + num + "]"), type)
FEND

//////////////////////////////////////////////////
// 【引数】
//   serial : 時間を表すシリアル値を指定 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION Hour(serial)
	RESULT = INT(serial * 24) MOD 24
FEND

//////////////////////////////////////////////////
// 【引数】
//   expr : 評価する式 
//   truepart : 評価した式がTrueのときに返す値 
//   falsepart : 評価した式がFalseのときに返す値 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION IIF(expr, truepart, falsepart)
	IFB EVAL(expr) THEN
		RESULT = truepart
	ELSE
		RESULT = falsepart
	ENDIF
FEND

//////////////////////////////////////////////////
// 【引数】
//   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

//////////////////////////////////////////////////
// 【引数】
//   date : 存在するかを調べる日付文字列。YYYYMMDD or YYYY/MM/DD or YYYY-MM-DDのいずれかの形式。 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION isDate(date)
	TRY
		GETTIME(0, date)
		RESULT = TRUE
	EXCEPT
		RESULT = FALSE
	ENDTRY
FEND

//////////////////////////////////////////////////
// 【引数】
//   
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION now()
	GETTIME()
	DIM datetime = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2
	RESULT = (GETTIME(0, datetime) - GETTIME(0, "1899/12/30")) / 86400
FEND

//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION reExecute(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
	DIM re = CREATEOLEOBJ("VBScript.RegExp")
	re.Pattern = Pattern
	re.IgnoreCase = IgnoreCase
	re.Global = Global
	RESULT = re.Execute(str)
FEND

//////////////////////////////////////////////////
// 【引数】
//   str1 : 置換される文字列 
//   str2 : 置換後の文字列 
//   Pattern : 置換する文字列のパターン 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION reReplace(str1, str2, Pattern, IgnoreCase = TRUE, Global = TRUE)
	DIM re = CREATEOLEOBJ("VBScript.RegExp")
	re.Pattern = Pattern
	re.IgnoreCase = IgnoreCase
	re.Global = Global
	RESULT = re.Replace(str1, str2)
FEND

//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION reTest(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
	DIM re = CREATEOLEOBJ("VBScript.RegExp")
	re.Pattern = Pattern
	re.IgnoreCase = IgnoreCase
	re.Global = Global
	RESULT = re.Test(str)
FEND

//////////////////////////////////////////////////
// 【引数】
//   inputs : 繰り返す文字列 
//   multiplier : inputsを繰り返す回数 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION strRepeat(inputs, multiplier)
	DIM res = ""
	FOR n = 1 TO multiplier
		res = res + inputs
	NEXT
	RESULT = res
FEND

//////////////////////////////////////////////////
// 【引数】
//   serial : シリアル値 
//   format : フォーマット 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION text(serial, format, hour12 = FALSE)
	HASHTBL startDate
	startDate["明治"] = "1868/01/25"
	startDate["大正"] = "1912/07/30"
	startDate["昭和"] = "1926/12/25"
	startDate["平成"] = "1989/01/08"
	startDate["令和"] = "2019/05/01"
	
	DIM baseDate = "1899/12/30"
	
	SELECT TRUE
		CASE reTest(format, "\[h+\]")
			Matches = reExecute(format, "\[(h+)\]")
			DIM hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
			RESULT = text(hour, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
		CASE reTest(format, "^h+$")
			Matches = reExecute(format, "^(h+)$")
			hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
			RESULT = text(hour MOD 24, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
		CASE reTest(format, "\[m+\]")
			Matches = reExecute(format, "\[(m+)\]")
			RESULT = text(serial * 1440, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
		CASE format = "m"
			GETTIME(serial, baseDate)
			RESULT = text(G_TIME_MM, "0")
		CASE format = "mm"
			GETTIME(serial, baseDate)
			RESULT = G_TIME_MM2
		CASE format = "n"
			GETTIME(serial, baseDate)
			RESULT = G_TIME_NN
		CASE format = "nn"
			GETTIME(serial, baseDate)
			RESULT = G_TIME_NN2
		CASE format = "s"
			GETTIME(serial, baseDate)
			RESULT = text(G_TIME_SS, "0")
		CASE format = "ss"
			GETTIME(serial, baseDate)
			RESULT = G_TIME_SS2
		CASE format = "yyyy"
			GETTIME(serial, baseDate)
			RESULT = G_TIME_YY4
		CASE format = "yy"
			GETTIME(serial, baseDate)
			RESULT = COPY(G_TIME_YY4, 3, 2)
		CASE format = "e"
			SELECT TRUE
				CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(serial, "yyyy") - 2018
				CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(serial, "yyyy") - 1988
				CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(serial, "yyyy") - 1925
				CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(serial, "yyyy") - 1911
				CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(serial, "yyyy") - 1867
			SELEND
		CASE format = "ee"
			SELECT TRUE
				CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(text(serial, "yyyy") - 2018, "00")
				CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(text(serial, "yyyy") - 1988, "00")
				CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(text(serial, "yyyy") - 1925, "00")
				CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(text(serial, "yyyy") - 1911, "00")
				CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(text(serial, "yyyy") - 1867, "00")
			SELEND
		CASE format = "g"
			SELECT TRUE
				CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "R"
				CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "H"
				CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "S"
				CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "T"
				CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "M"
			SELEND
		CASE format = "gg"
			RESULT = COPY(text(serial, "ggg"), 1, 1)
		CASE format = "ggg"
			SELECT TRUE
				CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "令和"
				CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "平成"
				CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "昭和"
				CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "大正"
				CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "明治"
			SELEND
		CASE format = "mmmmm"
			RESULT = COPY(text(serial, "mmmm"), 1, 1)
		CASE format = "mmmm"
			DIM month[] = "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
			RESULT = month[text(serial, "m") - 1]
		CASE format = "mmm"
			RESULT = COPY(text(serial, "mmmm"), 1, 3)
		CASE format = "dd"
			GETTIME(serial, baseDate)
			RESULT = text(G_TIME_DD2, "00")
		CASE format = "d"
			GETTIME(serial, baseDate)
			RESULT = text(G_TIME_DD, "0")
		CASE reTest(format, "^[ad]{3,4}$")
			Matches = reExecute(format, "([ad]{3,4})")
			GETTIME(serial, baseDate)
			RESULT = getWeekdayName(G_TIME_WW, Matches.Item(0).SubMatches(0))
		CASE reTest(format, "(0+\.?0+)?%")
			Matches = reExecute(format, "(0+\.?0+)?%")
			RESULT = text(serial * 100, Matches.Item(0).SubMatches(0)) + "%"
		CASE reTest(format, "^\[DBNum\d{1,4}\](.*?)$")
			Matches = reExecute(format, "^\[DBNum(\d{1,4})\](.*?)$")
			DIM value = VAL(Matches.Item(0).SubMatches(0))
			DIM sss = text(serial, Matches.Item(0).SubMatches(1))
			Matches = reExecute(sss, "(\D+)?(\d+)(\D+)?")
			DIM res = ""
			FOR m = 0 TO Matches.Count - 1
				serial = Matches.Item(m).SubMatches(1)
				SELECT value
					CASE 1, 2
						DIM n[][9] = "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九", + _
										"", "壱", "弐", "参", "四", "伍", "六", "七", "八", "九"
						DIM a[][3] = "", "十", "百", "千", + _
										"", "拾", "百", "阡"
						DIM b[][3] = "", "万", "億", "兆", + _
										"", "萬", "億", "兆"
						DIM r = ""
						DIM j = 0
						type = value - 1
						REPEAT
							DIM str = ""
							DIM n4 = serial MOD 10000
							FOR i = LENGTH(n4) TO 1 STEP -1
								s = COPY(n4, i, 1)
								IFB s = 1 AND a[type][LENGTH(n4)-i] <> "" THEN
									str = IIF(s, a[type][LENGTH(n4)-i], "") + str
								ELSE	
									str = n[type][s] + IIF(s, a[type][LENGTH(n4)-i], "") + str
								ENDIF
							NEXT
							IF str <> "" THEN r = str + b[type][j] + r
							j = j + 1
							serial = INT(serial / 10000)
						UNTIL serial = 0
						res = res + Matches.Item(m).SubMatches(0) + r + Matches.Item(m).SubMatches(2)
					CASE 3
						res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_FULLWIDTH) + Matches.Item(m).SubMatches(2)
					CASE 4
						res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_HALFWIDTH) + Matches.Item(m).SubMatches(2)
				SELEND
			NEXT
			RESULT = res
		CASE reTest(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
			Matches = reExecute(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
			DIM array = SPLIT(Matches.Item(0).SubMatches(1), "/")
			ampm = array[IIF(serial - INT(serial) >= 0.5, 1, 0)]
			hour12 = TRUE
			res = ""
			WITH Matches.Item(0)
				res = text(serial, .SubMatches(0), hour12) + ampm + text(serial, .SubMatches(2), hour12)
			ENDWITH
			RESULT = res
		CASE reTest(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
			Matches = reExecute(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
			FOR n = 0 TO Matches.Count - 1
				IF n = 0 THEN res = Matches.Item(n).SubMatches(0)
			NEXT
			FOR n = 0 TO Matches.Count - 1
				WITH Matches.Item(n)
					res = res + text(serial, .SubMatches(1), hour12) + .SubMatches(3)
				ENDWITH
			NEXT
			RESULT = res
		CASE format = "0/0"
			DIM separator = POS(".", serial)
			DIM g = 0
			IFB separator <> 0 THEN
				DIM keta = LENGTH(serial)
				DIM shift = POWER(10, keta - separator)
				IFB shift >= POWER(10, 15) THEN
					DIM position = 0
					FOR i = 0 TO 14
						IFB serial * POWER(10, i) - serial >= 1 THEN
							position = i
							BREAK
						ENDIF
					NEXT
					tmp = serial * POWER(10, position)
					FOR i = 1 TO 15
						r = (tmp * POWER(10, i)) / serial - (tmp / serial)
						a1 = tmp * POWER(10, i) - tmp
						IF a1 = INT(a1) THEN BREAK 
					NEXT
					DIM frac[] = a1, r
					g = GCD(frac)
					RESULT = (a1/g) + "/" + (r/g)
				ELSE
					DIM molecule = serial * shift	// 分子
					DIM denominator = shift		// 分母
					DIM nums[] = molecule, denominator
					g = GCD(nums)
					molecule = molecule / g
					denominator = denominator / g
					RESULT = molecule + "/" + denominator
				ENDIF
			ELSE
				RESULT = serial + "/1"
			ENDIF
		CASE reTest(format, "(0+)\.?(0+)?") AND UBound(SPLIT(format, ".")) <= 1 
			Matches = reExecute(format, "(0+)\.?(0+)?")
			len1 = LENGTH(Matches.Item(0).SubMatches(0))
			len2 = LENGTH(Matches.Item(0).SubMatches(1))
			DIM arr[] = LENGTH(INT(serial)), len1
			IFB POS(".", format) THEN
				RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX) + len2 + 1, len2), " ", "0")
			ELSE
				RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX)), " ", "0")
			ENDIF
	SELEND
FEND

//////////////////////////////////////////////////
// 【引数】
//   arrayname : 上限値を求める配列の名前 
//   dimension : 返す次元を示す整数 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION UBound(arrayname[], dimension = 1)
	RESULT = EVAL("RESIZE(arrayname" + strRepeat("[0]", dimension - 1) + ")")
FEND
結果
プレーンテキスト
■前回の実行日時
2022/03/07 02:09:07
使用関数

UWSC.INIのDefaultFontを変更する

UWSC
CONST ssfFONTS = 20

DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfFONTS)
DIM FolderItems = Folder.Items
DIM array[-1]

FOR FolderItem IN FolderItems
	arrayPush(array, FolderItem.Name)
NEXT

QSORT(array, QSRT_UNICODEA)
SHIFTARRAY(array, 1)
array[0] = "(なし)"

DIM filename = "C:\Users\" + BETWEENSTR(DOSCMD("SET"), "USERNAME=", "<#CR>") + "\AppData\Roaming\UWSC\UWSC.INI"
DIM str = SPLIT(READINI("SET", "DefaultFont", filename), ",")[0]
DIM font = SLCTBOX(SLCT_CMB OR SLCT_STR, 0, "フォントを選択してください。(現在:" + str + ")", array)

IF font = "(なし)" THEN font = ""
IF font <> -1 THEN WRITEINI("SET", "DefaultFont", font + ",", filename)

//////////////////////////////////////////////////
// 【引数】
//   array : 要素を追加する配列(参照引数) 
//   values : 追加する要素をvalue1から指定 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION arrayPush(var array[], value1 = EMPTY, value2 = EMPTY, value3 = EMPTY, value4 = EMPTY, value5 = EMPTY, value6 = EMPTY, value7 = EMPTY, value8 = EMPTY, value9 = EMPTY, value10 = EMPTY, value11 = EMPTY, value12 = EMPTY, value13 = EMPTY, value14 = EMPTY, value15 = EMPTY, value16 = EMPTY)
    DIM i = 1
    WHILE EVAL("value" + i) <> EMPTY
	  DIM res = RESIZE(array, UBound(array) + 1)
	  array[res] = EVAL("value" + i)
	  i = i + 1
	WEND
	RESULT = LENGTH(array)
FEND

//////////////////////////////////////////////////
// 【引数】
//   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

//////////////////////////////////////////////////
// 【引数】
//   inputs : 繰り返す文字列 
//   multiplier : inputsを繰り返す回数 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION strRepeat(inputs, multiplier)
	DIM res = ""
	FOR n = 1 TO multiplier
		res = res + inputs
	NEXT
	RESULT = res
FEND

//////////////////////////////////////////////////
// 【引数】
//   arrayname : 上限値を求める配列の名前 
//   dimension : 返す次元を示す整数 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION UBound(arrayname[], dimension = 1)
	RESULT = EVAL("RESIZE(arrayname" + strRepeat("[0]", dimension - 1) + ")")
FEND
使用関数

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
使用関数
解説

関連記事

DELETEINI関数 (スクリプト関数)
INIファイルのセクション、キーを削除します。
WRITEINI関数 (スクリプト関数)
INIファイルの書き込みを行います。
INI (自作関数)
INIファイル の読み書きを行います。