0

I have this command:

doskey cd = cd /d $* ^&^& echo "You are in: "%cd%

doskey cd = cd /d $* ^&^& title %cd%

When I paste this in CMD it will set the current cd and not dynamically when I recall the cd from the doskey.

Current output:

C:\>doskey cd = cd /d $* ^&^& echo "You are in: "%cd%

C:\>cd Users
You are in: C:\

C:\Users>

Desired output:

C:\>doskey cd = cd /d $* ^&^& echo "You are in: "%cd%

C:\>cd Users
You are in: C:\Users

C:\Users> 

What I have tried:

doskey cd = cd /d $* ^&^& echo "You are in: "%%cd%

doskey cd = cd /d $* ^&^& %cd%|echo "You are in: "

doskey cd = cd /d $* ^&^& cmd /k "echo \"You are in: \"%cd%" < don't want a new cmd session!

Finally I want to add this to my register

[HKEY_CLASSES_ROOT\Directory\Background\shell\cmdmenua]
@="Open Command Prompt Here (Admin)"
"Icon"="%SystemRoot%\\system32\\cmd.exe"

[HKEY_CLASSES_ROOT\Directory\Background\shell\cmdmenua\command]
@="powershell -NoLogo  -WindowStyle Hidden -Command \"$V = '%V'; Start-Process cmd \\\"/k  $($V.Substring(0,2)) & cd \"$V\" & Title Administrator: $V & doskey cd = cd /d `$* ^&^& title `$*\\\" -Verb RunAs\" "


[HKEY_CLASSES_ROOT\Directory\shell\cmdmenua]
@="Open Command Prompt Inside (Admin)"
"Icon"="%SystemRoot%\\system32\\cmd.exe"

[HKEY_CLASSES_ROOT\Directory\shell\cmdmenua\command]
@="powershell -NoLogo  -WindowStyle Hidden -Command \"$V = '%V'; Start-Process cmd \\\"/k  $($V.Substring(0,2)) & cd \"$V\" & Title Administrator: $V & doskey cd = cd /d `$* ^&^& title `$* \\\" -Verb RunAs\" "

source: https://github.com/ScriptsAndApps/Context-REG

  • First of all you should not add/modify directly within, `HKEY_CLASSES_ROOT`, you should replace that with `HKEY_LOCAL_MACHINE\SOFTWARE\Classes`. Better however, IMO, based upon your intended resulting subkey values and data would be to change that to `HKEY_CURRENT_USER\Software\Classes` instead. I say that because this sort of thing should not be a setting for all users of the PC. In addition if you use the latter, you could add the information to the registry using `%SystemRoot%\System32\reg.exe`, and that could be done without elevation, (`LOCAL_MACHINE` and `regedit.exe` require elevation). – Compo Mar 31 '23 at 23:34
  • What about `doskey cd=cd /D $* $T echo You are in: %^^CD%`? (not absolutely sure whether one `^` was sufficient) – aschipfl Apr 01 '23 at 15:01
  • @aschipfl YES this what I needed!! doskey cd=cd /D $* $T echo You are in: %^CD% and doskey cd=cd /D $* $T TITLE Administrator: %^CD% – justanotherpersonontheweb Apr 03 '23 at 15:09

1 Answers1

0

This is what I was looking for!

(
 @echo off
 doskey cd=cd /D $* $T echo You are in: %^CD% 
)

And this is what I will use

doskey cd=cd /D $* $T TITLE Administrator: %^CD%