1

我正在处理一个批处理文件,我需要添加这个条目:

doskey wfreerdp="C:\Program Files\wfreerdp\wfreerdp.exe" $*

到这个注册表:

HKCU\Software\Microsoft\Command Processor

我玩过 的选项reg add,但我根本无法让它工作。

我知道它应该是这样的:

reg add "HKCU\Software\Microsoft\Command Processor" /v doskey wfreerdp = "C:\Program Files\wfreerdp\wfreerdp.exe" $*

但我不知道是哪一个以及如何使用/t, /S, /d&/f标志。

如果我手动添加条目:

doskey wfreerdp = "C:\Program Files\wfreerdp\wfreerdp.exe" $*

它完美地工作。

或者,我尝试创建C:\bat\macros.doskey包含 doskey 命令的文件:

doskey wfreerdp = "C:\Program Files\wfreerdp\wfreerdp.exe" $*

以及批处理文件中的以下内容:

reg add "HKCU\Software\Microsoft\Command Processor" /v Autorun /d "doskey /macrofile=\"c:\bat\macros.doskey\"" /f

没有成功。

有小费吗?

4

1 回答 1

1

如果您尝试将doskey命令添加到命令提示符的 AutoRun 以便每次打开时都会运行cmd.exe,那么您需要运行以下命令:

reg add "HKCU\Software\Microsoft\Command Processor" /v "AutoRun" /d "doskey wfreerdp = \"C:\Program Files\wfreerdp\wfreerdp.exe\" $*"

让我们分解一下:

  • 从文档中cmd /?

    If /D was NOT specified on the command line, then when CMD.EXE starts, it
    looks for the following REG_SZ/REG_EXPAND_SZ registry variables, and if
    either or both are present, they are executed first.
    
        HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun
    
            and/or
    
        HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
    
  • 您已经知道您将密钥放入HKEY_CURRENT_USER\Software\Microsoft\Command Processor.

  • 开关指定要添加/修改的/v值名称,在这种情况下是AutoRun键。
  • /d开关指定该键应包含的内容,在本例中为doskey命令。
  • 由于您的命令包含引号 ( "),因此您需要对它们进行转义,以免命令行 ( \") 处理它们。
于 2018-10-23T17:15:11.857 回答