text
stringlengths
0
4.23k
Remarks
This command is similar to the UNIX utility SETENV.
You can use this command to set values for user and system environment variables from one of three sources (modes): Command Line Mode, Registry Mode, or File Mode.
This command writes variables to the master environment in the registry. 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.
You can't use this command to remove values added to the local or system environments. You can use this command with a variable name and no value to remove a corresponding value from the local environment.
REG_DWORD registry values are extracted and used in hexadecimal mode.
File mode supports the parsing of carriage return and line feed (CRLF) text files only.
Running this command on an existing variable removes any variable references and uses expanded values.
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.
This means that the content is cropped if you go over 1024 characters, and that the cropped text is what's applied to the target variable. If this cropped text is applied to an existing variable, it can result in loss of data previously held by the target variable.
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
sfc
Applies to: Windows Server 2022, Windows Server 2019, Windows Server 2016, Windows Server 2012 R2, Windows Server 2012
Scans and verifies the integrity of all protected system files and replaces incorrect versions with correct versions. If this command discovers that a protected file has been overwritten, it retrieves the correct version of the file from the systemroot\ folder, and then replaces the incorrect file.
Important
You must be logged on as a member of the Administrators group to run this command.
Syntax
sfc [/scannow] [/verifyonly] [/scanfile=<file>] [/verifyfile=<file>] [/offwindir=<offline windows directory> /offbootdir=<offline boot directory> /offlogfile=<log file path>]
Parameters
Parameter
Description
/scannow
Scans the integrity of all protected system files and repairs files with problems when possible.
/verifyonly
Scans the integrity of all protected system files, without performing repairs.
/scanfile <file>
Scans the integrity of the specified file (full path and filename) and attempts to repair any problems if they're detected.
/verifyfile <file>
Verifies the integrity of the specified file (full path and filename), without performing repairs.
/offwindir <offline windows directory>
Specifies the location of the offline windows directory, for offline repair.
/offbootdir <offline boot directory>
Specifies the location of the offline boot directory for offline repair.
/offlogfile=<log file path>
Specifies a location to store the log file other than the default.
/?
Displays help at the command prompt.
<file>
<file>
<offline windows directory>
<offline boot directory>
<log file path>