英文:
How do I add a variable to a doskey command that will read the variable after it executes (not get the current variable)
问题
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 directory, but it doesn't dynamically update when I recall the "cd" command from the doskey.
Desired output:
C:\>doskey cd = cd /d $* ^&^& echo "You are in: "%cd%
C:\>cd Users
You are in: C:\Users
C:\Users>
英文:
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\" "
答案1
得分: 0
这是我在寻找的内容!
(
@echo off
doskey cd=cd /D $* $T echo You are in: %^CD%
)
而这是我将要使用的
doskey cd=cd /D $* $T TITLE Administrator: %^CD%
英文:
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%
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论