다음을 통해 공유


setx

만들거나 프로그래밍 또는 스크립팅 필요 없이 사용자 또는 시스템 환경에서 환경 변수를 수정 합니다. 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
/초 <computer> 이름 또는 원격 컴퓨터의 IP 주소를 지정합니다. 백슬래시를 사용 하지 마십시오. 기본값은 로컬 컴퓨터의 이름입니다.
/유 [<___domain>\]<user name> 지정 된 사용자 계정의 자격 증명으로 스크립트를 실행합니다. 기본값은 시스템 사용 권한.
/피 [<password>] Specifies the password of the user account that is specified in the /u parameter.
<variable> 설정할 환경 변수의 이름을 지정 합니다.
<value> 환경 변수를 설정 하려는 값을 지정 합니다.
/케이 <path> 레지스트리 키에서 정보에 변수가 기반으로 설정 되도록 지정 합니다. The path uses the following syntax: \\<HIVE>\<KEY>\...\<Value>. 예를 들어 다음과 같은 경로를 지정할 수 있습니다. HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName
/에프 <filename> 사용 하 여 원하는 파일을 지정 합니다.
/ᅡ <X>,<Y> 검색 매개 변수로 절대 좌표와 오프셋을 지정합니다.
/아르 자형 <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.
/디 <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와 유사합니다.

  • 이 명령을 사용하여 명령줄 모드, 레지스트리 모드 또는 파일 모드의 세 가지 소스(모드) 중 하나에서 사용자 및 시스템 환경 변수의 값을 설정할 수 있습니다.

  • 이 명령은 레지스트리의 마스터 환경에 변수를 씁니다. 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