如何批量判断当前用户?

How do I determine the current user in batch?

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

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

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

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

用户名:

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

对于用户主目录:

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

echo只是打印一些东西的命令)