プログラミングやスクリプトを必要とせずに、ユーザーまたはシステム環境で環境変数を作成または変更します。 The Setx command also retrieves the values of registry keys and writes them to text files.
Note
このコマンドは、システム環境の値を直接かつ永続的に設定するための唯一のコマンドラインまたはプログラムの方法を提供します。 System environment variables are manually configurable through Control Panel or through a registry editor. The set command, which is internal to the command interpreter (Cmd.exe), sets user environment variables for the current console window only.
Syntax
setx [/s <computer> [/u [<domain>\]<user name> [/p [<password>]]]] <variable> <value> [/m]
setx [/s <computer> [/u [<domain>\]<user name> [/p [<password>]]]] <variable>] /k <path> [/m]
setx [/s <computer> [/u [<domain>\]<user name> [/p [<password>]]]] /f <filename> {[<variable>] {/a <X>,<Y> | /r <X>,<Y> <String>} [/m] | /x} [/d <delimiters>]
Parameters
Parameter | Description |
---|---|
/s <computer> |
リモート コンピューターの名前または IP アドレスを指定します。 円記号は使用しないでください。 既定値は、ローカル コンピューターの名前です。 |
/u [<domain>] |
指定したユーザー アカウントの資格情報を使用してスクリプトを実行します。 既定値はシステムのアクセス許可です。 |
/p [<password> ] |
Specifies the password of the user account that is specified in the /u parameter. |
<variable> |
設定する環境変数の名前を指定します。 |
<value> |
環境変数を設定する値を指定します。 |
/k <path> |
レジストリ キーからの情報に基づいて変数を設定することを指定します。 The path uses the following syntax: \\<HIVE>\<KEY>\...\<Value> . たとえば、次のパスを指定できます: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName |
/f <filename> |
使用するファイルを指定します。 |
/ある <X>,<Y> |
絶対座標とオフセットを検索パラメーターとして指定します。 |
/r <X>,<Y> <String> |
Specifies relative coordinates and offset from String as search parameters. |
/m | システム環境で変数を設定することを指定します。 既定の設定はローカル環境です。 |
/x | Displays file coordinates, ignoring the /a, /r, and /d command-line options. |
/d <delimiters> |
Specifies delimiters such as , or \ to be used in addition to the four built-in delimiters — SPACE, TAB, ENTER, and LINEFEED. 有効な区切り記号には、任意の ASCII 文字が含まれます。 区切り記号の最大数は、組み込みの区切り記号を含めて 15 です。 |
/? | コマンド プロンプトにヘルプを表示します。 |
Remarks
このコマンドは UNIX ユーティリティー SETENV に似ています。
このコマンドを使用すると、コマンド ライン モード、レジストリ モード、またはファイル モードの 3 つのソース (モード) のいずれかから、ユーザー環境変数とシステム環境変数の値を設定できます。
このコマンドは、レジストリ内のマスター環境に変数を書き込みます。 Variables set with setx variables are available in future command windows only, not in the current command window.
HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE are the only supported hives. REG_DWORD, REG_EXPAND_SZ, REG_SZ, and REG_MULTI_SZ are the valid RegKey data types.
If you gain access to REG_MULTI_SZ values in the registry, only the first item is extracted and used.
このコマンドを使用して、ローカル環境またはシステム環境に追加された値を削除することはできません。 このコマンドを変数名と値なしで使用して、対応する値をローカル環境から削除できます。
REG_DWORDレジストリ値が抽出され、16 進数モードで使用されます。
ファイル モードでは、復帰テキスト ファイルと改行 (CRLF) テキスト ファイルの解析のみがサポートされます。
既存の変数でこのコマンドを実行すると、変数参照が削除され、展開された値が使用されます。
For instance, if the variable %PATH% has a reference to %JAVADIR%, and %PATH% is manipulated using setx, %JAVADIR% is expanded and its value is assigned directly to the target variable %PATH%. This means that future updates to %JAVADIR% will not be reflected in the %PATH% variable.
Be aware there's a limit of 1024 characters when assigning contents to a variable using setx.
つまり、1024 文字を超える場合はコンテンツがトリミングされ、トリミングされたテキストがターゲット変数に適用されることを意味します。 このトリミングされたテキストが既存の変数に適用されると、ターゲット変数によって以前に保持されていたデータが失われる可能性があります。
Examples
To set the MACHINE environment variable in the local environment to the value Brand1, type:
setx MACHINE Brand1
To set the MACHINE environment variable in the system environment to the value Brand1 Computer, type:
setx MACHINE Brand1 Computer /m
To set the MYPATH environment variable in the local environment to use the search path defined in the PATH environment variable, type:
setx MYPATH %PATH%
To set the MYPATH environment variable in the local environment to use the search path defined in the PATH environment variable after replacing ~ with %, type:
setx MYPATH ~PATH~
To set the MACHINE environment variable in the local environment to Brand1 on a remote computer named computer1, type:
setx /s computer1 /u maindom\hiropln /p p@ssW23 MACHINE Brand1
To set the MYPATH environment variable in the local environment to use the search path defined in the PATH environment variable on a remote computer named computer1, type:
setx /s computer1 /u maindom\hiropln /p p@ssW23 MYPATH %PATH%
To set the TZONE environment variable in the local environment to the value found in the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName registry key, type:
setx TZONE /k HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName
To set the TZONE environment variable in the local environment of a remote computer named computer1 to the value found in the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName registry key, type:
setx /s computer1 /u maindom\hiropln /p p@ssW23 TZONE /k HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName
To set the BUILD environment variable in the system environment to the value found in the HKEY_LOCAL_MACHINE\Software\Microsoft\WindowsNT\CurrentVersion\CurrentBuildNumber registry key, type:
setx BUILD /k HKEY_LOCAL_MACHINE\Software\Microsoft\WindowsNT\CurrentVersion\CurrentBuildNumber /m
To set the BUILD environment variable in the system environment of a remote computer named Computer1 to the value found in the HKEY_LOCAL_MACHINE\Software\Microsoft\WindowsNT\CurrentVersion\CurrentBuildNumber registry key, type:
setx /s computer1 /u maindom\hiropln /p p@ssW23 BUILD /k HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\CurrentBuildNumber /m
To display the contents of a file named Ipconfig.out, along with the contents' corresponding coordinates, type:
setx /f ipconfig.out /x
To set the IPADDR environment variable in the local environment to the value found at the coordinate 5,11 in the Ipconfig.out file, type:
setx IPADDR /f ipconfig.out /a 5,11
To set the OCTET1 environment variable in the local environment to the value found at the coordinate 5,3 in the Ipconfig.out file with delimiters #$*., type:
setx OCTET1 /f ipconfig.out /a 5,3 /d #$*.
To set the IPGATEWAY environment variable in the local environment to the value found at the coordinate 0,7 with respect to the coordinate of Gateway in the Ipconfig.out file, type:
setx IPGATEWAY /f ipconfig.out /r 0,7 Gateway
To display the contents of the Ipconfig.out file, along with the contents' corresponding coordinates, on a computer named computer1, type:
setx /s computer1 /u maindom\hiropln /p p@ssW23 /f ipconfig.out /x