Setx - 環境変数の設定
setx
- C:\Windows\system32\setx.exe /?
Output:
SetX の使用法は 3 とおりあります:
構文 1:
SETX [/S システム [/U [ドメイン\]ユーザー [/P [パスワード]]]] 変数 値 [/M]
構文 2:
SETX [/S システム [/U [ドメイン\]ユーザー [/P [パスワード]]]]
変数 /K レジストリパス [/M]
構文 3:
SETX [/S システム [/U [ドメイン\]ユーザー [/P [パスワード]]]]
/F ファイル {変数 {/A x,y | /R x,y 文字列}[/M] | /X} [/D 区切り文字]
説明:
ユーザーまたはシステムの環境の中で環境変数を作成または
変更します。引数、レジストリ キー、またはファイル入力を
もとに変数を設定することができます。
パラメーター一覧:
/S システム 接続先のリモート システムを指定します。
/U [ドメイン\]ユーザー コマンドが実行されるユーザー
コンテキストを指定します。
/P [パスワード] 指定されたユーザーのコンテキストのパスワード
を指定します。省略すると入力が促されます。
変数 設定する環境変数を指定します。
値 環境変数に割り当てられる値を指定
します。
/K レジストリパス レジストリ キーからの情報を基に変数が
設定されることを指定します。
パスは hive\key\...\value の形式で指定します。
例:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\
Control\TimeZoneInformation\StandardName.
/F ファイル 使用するテキスト ファイルの名前を指定し
ます。
/A x、y ファイルの絶対座標 (行 X、項目 Y) を
パラメーターとして指定し、ファイル内を検索
します。
/R x,y 文字列 "文字列" を検索パラメーターとして
ファイルへの相対座標を指定します。
/M 変数をシステム全体 (HKEY_LOCAL_MACHINE)
の環境で設定することを指定します。
既定では、HKEY_CURRENT_USER 環境で変数
を設定するように設定されています。
/X x y 座標でファイルの内容を表示します。
/D 区切り文字 "," や "\" など、追加の区切り文字を指定し
ます。ビルトインの区切り文字は空白、タブ、
キャリッジ リターン、ラインフィードです。
ASCII 文字はどれでも追加の区切り文字として
使用できます。区切り文字は、ビルトインの
ものも含めて最大 15 個まで指定できます。
/? このヘルプを表示します。
注意: 1) SETX は、レジストリの中のマスター環境に変数を書き込みます。
2) ローカル システム上では、このツールで作成または変更した
変数は、現在のコマンド ウィンドウでは利用できませんが、
その後のコマンド ウィンドウで利用できます。
3) リモート システム上では、このツールで作成または変更した
変数は次のログオン セッションで利用できます。
4) 有効なレジストリ キー データの種類は REG_DWORD、REG_EXPAND_SZ、
REG_SZ, REG_MULTI_SZ です。
5) サポートされているハイブは HKEY_LOCAL_MACHINE (HKLM)、
HKEY_CURRENT_USER (HKCU) です。
6) 区切り文字は大文字と小文字を区別します。
7) REG_DWORD 値は、レジストリから 10 進数形式で
抽出されます。
例:
SETX MACHINE COMPAQ
SETX MACHINE "COMPAQ COMPUTER" /M
SETX MYPATH "%PATH%"
SETX MYPATH ~PATH~
SETX /S system /U user /P password MACHINE COMPAQ
SETX /S system /U user /P password MYPATH ^%PATH^%
SETX TZONE /K HKEY_LOCAL_MACHINE\System\CurrentControlSet\
Control\TimeZoneInformation\StandardName
SETX BUILD /K "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows
NT\CurrentVersion\CurrentBuildNumber" /M
SETX /S system /U user /P password TZONE /K HKEY_LOCAL_MACHINE\
System\CurrentControlSet\Control\TimeZoneInformation\
StandardName
SETX /S system /U user /P password BUILD /K
"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\
CurrentVersion\CurrentBuildNumber" /M
SETX /F ipconfig.out /X
SETX IPADDR /F ipconfig.out /A 5,11
SETX OCTET1 /F ipconfig.out /A 5,3 /D "#$*."
SETX IPGATEWAY /F ipconfig.out /R 0,7 Gateway
SETX /S system /U user /P password /F c:\ipconfig.out /X
SetX has three ways of working:
Syntax 1:
SETX [/S system [/U [domain\]user [/P [password]]]] var value [/M]
Syntax 2:
SETX [/S system [/U [domain\]user [/P [password]]]] var /K regpath [/M]
Syntax 3:
SETX [/S system [/U [domain\]user [/P [password]]]]
/F file {var {/A x,y | /R x,y string}[/M] | /X} [/D delimiters]
Description:
Creates or modifies environment variables in the user or system
environment. Can set variables based on arguments, regkeys or
file input.
Parameter List:
/S system Specifies the remote system to connect to.
/U [domain\]user Specifies the user context under which
the command should execute.
/P [password] Specifies the password for the given
user context. Prompts for input if omitted.
var Specifies the environment variable to set.
value Specifies a value to be assigned to the
environment variable.
/K regpath Specifies that the variable is set based
on information from a registry key.
Path should be specified in the format of
hive\key\...\value. For example,
HKEY_LOCAL_MACHINE\System\CurrentControlSet\
Control\TimeZoneInformation\StandardName.
/F file Specifies the filename of the text file
to use.
/A x,y Specifies absolute file coordinates
(line X, item Y) as parameters to search
within the file.
/R x,y string Specifies relative file coordinates with
respect to "string" as the search parameters.
/M Specifies that the variable should be set in
the system wide (HKEY_LOCAL_MACHINE)
environment. The default is to set the
variable under the HKEY_CURRENT_USER
environment.
/X Displays file contents with x,y coordinates.
/D delimiters Specifies additional delimiters such as ","
or "\". The built-in delimiters are space,
tab, carriage return, and linefeed. Any
ASCII character can be used as an additional
delimiter. The maximum number of delimiters,
including the built-in delimiters, is 15.
/? Displays this help message.
NOTE: 1) SETX writes variables to the master environment in the registry.
2) On a local system, variables created or modified by this tool
will be available in future command windows but not in the
current CMD.exe command window.
3) On a remote system, variables created or modified by this tool
will be available at the next logon session.
4) The valid Registry Key data types are REG_DWORD, REG_EXPAND_SZ,
REG_SZ, REG_MULTI_SZ.
5) Supported hives: HKEY_LOCAL_MACHINE (HKLM),
HKEY_CURRENT_USER (HKCU).
6) Delimiters are case sensitive.
7) REG_DWORD values are extracted from the registry in decimal
format.
Examples:
SETX MACHINE COMPAQ
SETX MACHINE "COMPAQ COMPUTER" /M
SETX MYPATH "%PATH%"
SETX MYPATH ~PATH~
SETX /S system /U user /P password MACHINE COMPAQ
SETX /S system /U user /P password MYPATH ^%PATH^%
SETX TZONE /K HKEY_LOCAL_MACHINE\System\CurrentControlSet\
Control\TimeZoneInformation\StandardName
SETX BUILD /K "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows
NT\CurrentVersion\CurrentBuildNumber" /M
SETX /S system /U user /P password TZONE /K HKEY_LOCAL_MACHINE\
System\CurrentControlSet\Control\TimeZoneInformation\
StandardName
SETX /S system /U user /P password BUILD /K
"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\
CurrentVersion\CurrentBuildNumber" /M
SETX /F ipconfig.out /X
SETX IPADDR /F ipconfig.out /A 5,11
SETX OCTET1 /F ipconfig.out /A 5,3 /D "#$*."
SETX IPGATEWAY /F ipconfig.out /R 0,7 Gateway
SETX /S system /U user /P password /F c:\ipconfig.out /X
Return Code: 0
C:\Windows\system32\setx.exe
c:\>ver
Microsoft Windows [Version 10.0.19045.2075]
| File | Info |
|---|---|
| File Size | 58368bytes |
| Creation Time | 2019/12/07 18:09:34 |
| LastWrite Time | 2019/12/07 18:09:34 |
| ProductVersion | 10.0.19041.1889 |
| FileVersion | 10.0.19041.1889 (WinBuild.160101.0800) |
| Hash | Value |
|---|---|
| MD5 | 7d809ccfec9a92bc2c6b35247473245b |
| SHA1 | ad79e24ba010465e964941573289408ffc342ed0 |
| SHA224 | 6c8c3146b2878e922ce98b44cb6b0e744928c43c000b254477ff4164 |
| SHA256 | f207f3bf4b4d3f2c73db94baa69ce81cc0675f7c638b5d747c8c46f4323a2f44 |
| SHA384 | ae791b6656f7219655a8cff0138fea117a31979218778dad8e43a0ce070a94ac0a0333ecbc2c82979e25c79ac35312a6 |
| SHA512 | 1da8f5009437038080526073f99f69d27c96fb3071a78e16ec002026ecaabca337d16cdfd523cd2eb2a6789228da987e948e94570352ee770fcbfbffa1799e1a |