How do I add a variable to a doskey command that will read the variable after it executes (not get the current variable)

huangapple go评论58阅读模式
英文:

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 $* ^&amp;^&amp; cmd /k &quot;echo \&quot;You are in: \&quot;%cd%&quot; < don't want a new cmd session!

Finally I want to add this to my register

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

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


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

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

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

答案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%

huangapple
  • 本文由 发表于 2023年3月31日 23:47:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75900447.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定