Windows: is there an autoexit for cmd.exe as if there were an automatic execution?

In the windows when you create a value. autorun in registry key HKEY_CURRENT_USER Software Microsoft Command Processor and put it to, shall we say, echo Hello from autoruninvoking cmd.exe will execute that line in the invocation.

There is an equivalent autoexitAs a value to execute in closing cmd.exe?

I have tried autoexit, autoclose, autoquit, exit, onexit, onquit Y leave unlucky

What I want to achieve is to save the current directory when leaving cmd.exe configuring the (imaginary) autoexit registration value for setx _LAST_DIR "% cd%", so you can remember it in the next invocation with cd "% _LAST_DIR%" or in a Command indicator Last Dir.lnk file with the Start at entry box set in % _LAST_DIR%.

My current solution is to have a batch file in the PATH, myexit.cmd:

@setx _LAST_DIR "% CD%"

I have to remember to invoke instead of leaving, if I want to save the directory.