[Undocumented] Variables __CD__ & __APPDIR__

Microsoft Windows
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Been thanked: 2 times
Contact:

[Undocumented] Variables __CD__ & __APPDIR__

Post by MigrationUser »

23 Dec 2014 21:48
carlos


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

%__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__%

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

Code: Select all

Echo %__CD__%
Carlos.

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

----------------------------

#2 23 Dec 2014 22:27
DigitalSnow


Interesting. How did you come across it? This popped up in a search I ran for __AppData__
http://manaeff.ru/forum/viewtopic.php?f=3&t=518
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
npocmaka


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
npocmaka


one more barely documented variable:

USERDOMAIN_ROAMINGPROFILE

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
klint


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