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评论86阅读模式
英文:

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:

  1. C:\>doskey cd = cd /d $* ^&^& echo "You are in: "%cd%
  2. C:\>cd Users
  3. You are in: C:\Users
  4. 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:

  1. C:\>doskey cd = cd /d $* ^&^& echo "You are in: "%cd%
  2. C:\>cd Users
  3. You are in: C:\
  4. C:\Users>

Desired output:

  1. C:\>doskey cd = cd /d $* ^&^& echo "You are in: "%cd%
  2. C:\>cd Users
  3. You are in: C:\Users
  4. 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

  1. [HKEY_CLASSES_ROOT\Directory\Background\shell\cmdmenua]
  2. @=&quot;Open Command Prompt Here (Admin)&quot;
  3. &quot;Icon&quot;=&quot;%SystemRoot%\\system32\\cmd.exe&quot;
  4. [HKEY_CLASSES_ROOT\Directory\Background\shell\cmdmenua\command]
  5. @=&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;
  6. [HKEY_CLASSES_ROOT\Directory\shell\cmdmenua]
  7. @=&quot;Open Command Prompt Inside (Admin)&quot;
  8. &quot;Icon&quot;=&quot;%SystemRoot%\\system32\\cmd.exe&quot;
  9. [HKEY_CLASSES_ROOT\Directory\shell\cmdmenua\command]
  10. @=&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

这是我在寻找的内容!

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

而这是我将要使用的

  1. doskey cd=cd /D $* $T TITLE Administrator: %^CD%
英文:

This is what I was looking for!

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

And this is what I will use

  1. 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:

确定