[Undocumented] Variables __CD__ & __APPDIR__

Microsoft Windows
Post Reply
User avatar
Posts: 336
Joined: 2021-Jul-12, 1:37 pm

[Undocumented] Variables __CD__ & __APPDIR__

Post by MigrationUser »

23 Dec 2014 21:48

Hello. I found a new undocumented variable, in addition to %__CD__% it is %__APPDIR__%

have the path (with a backlash at the end) where the application that request the variable is located.
For example, if we run C:\Windows\system32\cmd.exe , %__APPDIR__% will expand to C:\Windows\system32\
If we copy cmd to C:\dev\cmd.exe and run it %__APPDIR__% will expand to C:\dev\

Code: Select all

Echo %__APPDIR__%

Also I re document the %__CD__%

have the current directory (with a backlash at the end) of the application that request the variable.

Code: Select all

Echo %__CD__%

Last edited by carlos (23 Dec 2014 21:51)


#2 23 Dec 2014 22:27

Interesting. How did you come across it? This popped up in a search I ran for __AppData__
but with a description about Internet Explorer.


#3 24 Dec 2014 00:19
Simon Sheppard

Theres some more detail in this DOSTIPS thread

I've added this to the 'undocumented variables' here: https://ss64.com/nt/syntax-variables.html


#4 24 Dec 2014 19:20

I've checked ntdll.dll strings and found also FIRMWARE_TYPE variable which available only from windows 8/2012 and above.
It should check boot type of the system:

It should have 4 values : Legacy ,UEFI,Not implemented ,Unknown (default should be legacy)

https://docs.microsoft.com/en-us/previo ... (v=win.10)
https://web.archive.org/web/20140331091 ... /what-uefi [archive link]


#5 29 Dec 2014 09:35

one more barely documented variable:


It appears with installation of kb-2664408 fix which is applicable from vista/2008 and above.


#6 03 Jan 2015 14:36
Simon Sheppard

Thanks npocmaka, I have updated the page with these extra 2 variables now.


#7 19 Jan 2016 18:06

The __APPDIR__ and __CD__ variable names can be used by any Windows process, not just cmd.exe. For example, you can write a C++ application that calls the WinApi function GetEnvironmentVariable and it will return the current values for the above two variables. By contrast, the variable "CD" doesn't work because it's only defined in cmd.exe.
Post Reply