3

With starting command prompt with cmd /e:off or using setlocal disableExtensions (in a batch file) or excluding them through the registry value HKEY_CURRENT_USER\Software\Microsoft\Command Processor\EnableExtensions (by setting the value to 0) the feature called "extensions" is disabled (turned on by default).

What are the changes that this causes?

aschipfl
  • 33,626
  • 12
  • 54
  • 99
npocmaka
  • 55,367
  • 18
  • 148
  • 187

1 Answers1

8

Turning off extensions affects some built-in environment variables and some internal for the command prompt commands. I've never seen full list of non-working variables ,though the internal commands are more or less well documented - but never put in a list together.

I. I'll start with the variables:

%CD% is not working. But surprisingly %__CD__% works though it sets additional backslash at the end.

%CMDEXTVERSION% - logical at some degree as the command prompt is reduced only to its earlier versions

%CMDCMDLINE% - command line could be retrieved with some external tools that will give you information about the current PID.

%ERRORLEVEL% - as alternative %=ExitCode% can be used. Also %=ExitCodeAscii% if the exit code is above 32. IF ERRORLEVEL also still works.

%DATE% and %TIME% - though in disabled extensions mode you won't be able to assign the current date to a variable there are at least a lot of ways to display it.

%RANDOM%

%HighestNumaNodeNumber% - this was the biggest surprise for me as this variable was introduced in the newer versions of Windows when the support for multicore processors was added. It is highly related to the /NODE switch of the START command which is still working.

II. And the commands:

TAB is no longer autocomplete file names.Only in command prompt.

Starting a file by its extension - in disabled extensions mode the cmd will not get into account the HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts and //HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ext\OpenWithList and will start directly only a "programs" - i.e. extensions described in %PATHEXT% variable.

Variable manipulation - replacements and substrings will not work with disabled extensions. Which means only with disabled extensions you can print the value of %=::% - undocumented variable that is defined only when the command prompt is not started with admin privileges.

ASSOC and FTYPE - not available under disabled extensions - related to the first point here.

CALL - no longer able to call labels but only other scripts.Argument modifiers are no longer supported (also in FOR command) - %~0, %~dp0, %~n0 will no longer working. Only plain access with %0,%1 ..

COLOR - no longer available. Though colors can be changed with other scripts.

IF - /I is not working. Three letter comparison operators (that can be used for integer comparisons) are not available - only ==. CMDEXTVERSION is not part of the options as well as DEFINED.

EXIT - Exit /b works ,but prints an error message as it tries to find the :EOF label. The printed error is not 'officially' documented.Only observable in batch files.

FOR - reduced to only basic for loops - the additional switches /F , /D , /R , /L are not available. Token modifiers will no longer working in a similar fashion of CALL arguments.

SHIFT - the /N switch is not working ,though is not 'officially' documented.

GOTO - :EOF label is not available anymore.

SET - switches /P and /A are no more working. Does not accept double quotes as part of the command (e.g. set "variable=value" will result in an error). Listing variables starting with a string is no longer possible (e.g. set path will cause an error). Only plain setting a variable value.

PUSHD - does no longer map temporary drives to UNC paths, and POPD does not delete such drives. Not officially documented.

PROMPT - does not support $+ and $M special codes

The HELP command deserves a note as it will not detect if the extensions are on or off and will print help messages as the extensions are available.

As COLOR , ASSOC , FTYPE (and IF DEFINED is not working) are the only commands turned off with disabled extensions are one of the best option to check if they are enabled (though COLOR will change the colour scheme). But their output will be too big without the help message and help message is also not so small - which means even the redirection to null will slow down the check.

Eventually this also can be used to detect if the extensions are enabled:

call ::eof >nul 2>&1 && (
    echo extensions are enabled
)||(
    echo extensions are disabled
)

Or using assoc or ftype with an extension that will be available by default:

assoc .bat >nul 2>&1 && (
    echo extensions are enabled
)||(
    echo extensions are disabled
)

with ftype:

ftype batfile >nul 2>&1 && (
    echo extensions are enabled
)||(
    echo extensions are disabled
)
npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • 2
    `pushd` does no longer map temporary drives to UNC paths, and `popd` does not delete such drives; `prompt` does not support `$+` and `$M` codes… – aschipfl Mar 07 '22 at 08:05
  • @aschipfl - thanks. I'll include that too. – npocmaka Mar 07 '22 at 08:11
  • 1
    `%HighestNumaNodeNumber%` appears quite logical considering that it is a dynamic variable just like all the others that are unavailable with the command extensions disabled – refer to [SS64](https://ss64.com/nt/syntax-variables.html)… – aschipfl Mar 07 '22 at 11:47
  • 1
    The different behavior of command __CD__ as described by its usage help is missing in the answer. Example: There is the directory. `C:\Temp` and it contains `Test.cmd` with 1. `setlocal DisableExtensions`, 2. `C:`, 3. `cd C:\TEMP`, 4. `dir` and last `endlocal`. On execution of `C:\Temp\Test.cmd` is displayed `C:\TEMP>dir` and `Directory of C:\TEMP` and `C:\TEMP>endlocal` (three times `C:\TEMP` in upper case) while with first line changed to `setlocal EnableExtensions` is output `C:\Temp>dir` and `Directory of C:\Temp` and `C:\Temp>endlocal` (three times with `C:\Temp` as in file system). – Mofi Mar 11 '22 at 18:50
  • 1
    There is written: "`PUSHD` - does no longer map temporary drives to UNC paths, and `POPD` does not delete such drives. Not officially documented." The last sentence is not true because of the usage helps output on running `pushd /?` and `popd /?` document this changed behavior with UNC paths handling on disabled command extensions. This comment is deleted by me on answer updated accordingly with deleting the sentence: "Not officially documented." – Mofi Mar 12 '22 at 18:43
  • @Mofi - thanks. I'll update it tomorrow. – npocmaka Mar 12 '22 at 22:27
  • @Mofi, more important than the case stuff is the fact that `cd` requires paths with spaces to be quoted when command extensions are disabled (as also mentioned in the usage information)… – aschipfl Mar 13 '22 at 16:30
  • There are also changes in the following commands (typing `cmd /?` shows a (more or less) list of them): `del`/`erase`, `md`/`mkdir`, `setlocal` and `endlocal`, `start`… – aschipfl Mar 13 '22 at 17:12
  • @aschipfl Yes, your are 100% right. It is documented in usage help and really necessary to enclose a folder path in `"` containing one or more spaces on using command __CD__ with disabled command extensions. This comment will be deleted by me also on answer updated by npocmaka. – Mofi Mar 14 '22 at 15:05