【问题标题】:How do I determine the current user in batch?如何批量确定当前用户?
【发布时间】:2015-07-03 18:34:36
【问题描述】:

我正在制作一些安装系统,我希望它找到当前用户,并转到用户的文件夹。因此,例如,如果当前用户是 Joe,那么我希望它将目录更改为 Joe 的文件夹,而不是 Mary 的。

【问题讨论】:

    标签: batch-file directory


    【解决方案1】:

    %username% 系统变量包含当前用户名。

    您也可以使用%userprofile% 代替C:\Users\<user>

    【讨论】:

      【解决方案2】:

      我会说这完全取决于您使用的系统:

      对于用户名:

      • 窗口:echo %username%
      • Linux:echo "$USER"
      • Java:System.getProperty("user.name")

      对于用户主目录:

      • Windows:echo %userprofile%
      • Linux:echo "$HOME"
      • Java:System.getProperty("user.home")

      echo 只是打印东西的命令)

      【讨论】:

      • 批处理是 Windows 独有的。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-03
      • 2020-12-07
      • 1970-01-01
      相关资源
      最近更新 更多